gpt4 book ai didi

flutter - 如何在 flutter 中获得渐变底部导航选项卡?

转载 作者:行者123 更新时间:2023-12-05 00:56:45 26 4
gpt4 key购买 nike

pub上有一个包 https://pub.dev/packages/gradient_bottom_navigation_bar

但是很久没有更新了。那么,有没有办法创建自己的带有渐变效果的自定义导航栏?

像这样... enter image description here

最佳答案

Flutter 一切皆有可能,一种选择是在您的 BottomNavigationBar 中使用透明背景并将其放入带有 BoxDecoration 的容器中,尝试下一个:

import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Text("Hello"),
),
bottomNavigationBar: _createBottomNavigationBar(),
),
);
}

Widget _createBottomNavigationBar() {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xFF00D0E1), Color(0xFF00B3FA)],
begin: Alignment.topLeft,
end: Alignment.topRight,
stops: [0.0, 0.8],
tileMode: TileMode.clamp,
),
),
child: BottomNavigationBar(
currentIndex: 0,
onTap: (index) {},
showUnselectedLabels: false,
backgroundColor: Colors.transparent,
type: BottomNavigationBarType.fixed,
elevation: 0,
unselectedItemColor: Colors.white,
selectedIconTheme: IconThemeData(color: Colors.white),
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text(
"Home",
style: TextStyle(color: Colors.white),
),
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
title: Text(
"Business",
style: TextStyle(color: Colors.white),
),
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
title: Text(
"School",
style: TextStyle(color: Colors.white),
),
),
],
),
);
}
}

关于flutter - 如何在 flutter 中获得渐变底部导航选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61717440/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com