如何在没有包的情况下向默认的bottomNavigationBar添加渐变?
bottomNavigationBar: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [Colors.grey[600], Colors.grey[900]])),
height: getBottomBarSize(),
child: BottomAppBar(
//color: Colors.grey[900],
child: getChild()),
),
我尝试过这个,但不起作用。有没有另一种方法可以尝试,而无需编写自己的导航栏或使用包?
谢谢:)
最佳答案
这是因为 BottomAppBar
小部件的默认行为。您实际上并没有看到 Container
渐变,因为 BottomAppBar
颜色隐藏了它。
像这样反转你的小部件顺序
bottomNavigationBar: BottomAppBar(
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [Colors.grey[600], Colors.grey[900]],
),
),
height: getBottomBarSize(),
child: getChild(),
),
),
关于flutter - 如何给bottomNavigationBar添加渐变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65755013/