flutter - 如何给bottomNavigationBar添加渐变?

标签 flutter

如何在没有包的情况下向默认的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/

相关文章:

flutter - 如果参数为空,则使用默认值

firebase - 如何从 Firebase 存储文件中获取 url?

android - 在 Flutter 中的操作栏和标题之间添加一些空间

dart - 如何在 flutter 中截取屏幕外的小部件的屏幕截图?

flutter/Dart : How to make data load on the first tab when launching application?

dictionary - 有没有办法在map/forEach中标识当前索引

dart - Sembast 删除所有文件的最佳方法

flutter - 使用 Dart::ffi 在带有 native 函数的 flutter 包中测试库函数

flutter - 使用 flutter 时 Azure Devops 中的奇怪构建错误

flutter - 如何在 Flutter 中显示一段代码,保持所有缩进和换行不变?