[英]How to get gradient bottom navigation tab in flutter?
There is a package on pub https://pub.dev/packages/gradient_bottom_navigation_bar在pub https://pub.dev/packages/gradient_bottom_navigation_bar 上有一个 package
but this is not updated for a very long time.但是这个已经很久没有更新了。 So, is there a way to create own custom navigation bar with a gradient effect?
那么,有没有办法创建自己的具有渐变效果的自定义导航栏?
All it's possible with Flutter, one option could be use a transparent background in your BottomNavigationBar and put it inside a container with a BoxDecoration, try the next: 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),
),
),
],
),
);
}
}
I've got a more basic solution.我有一个更基本的解决方案。 You can check this DartPad .
你可以检查这个 DartPad 。
The end result:最终结果:
The trick is this:诀窍是这样的:
BottomNavigationBar
as transparent.BottomNavigationBar
的背景颜色设置为透明。Stack
.Stack
包裹它。Container
as first child to the Stack
.Container
作为第一个孩子到Stack
。Container
's decoration to gradient.Container
的装饰设置为渐变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.