我有一个有Drawer个屏幕的应用程序.主屏幕包含以下AppBar:

AppBar(
   foregroundColor: Colors.white,
   backgroundColor: Colors.green,
   elevation: 0,      
   actions: // actions here
)

我想保留这AppBar美元,因为我在这里有行动.我不希望它有任何 colored颜色 .所以我在应用程序Scaffold中添加了以下代码:

extendBodyBehindAppBar: true,

它工作得很好,现在AppBar是看不见的,动作是可见的.然而,当我在抽屉里做一些事情并关闭它时,AppBar开始有奇怪的 colored颜色 (不是每次都是).我发现它仍然是透明的,但elevation发生了一些事情,所以它现在的行为就像它有elevation: 1.0一样.有没有人能建议一下,如何解决这种奇怪的行为?我认为对于AppBar和屏幕的其余部分来说,零elevation可能都有问题,当Drawer出现在屏幕上方然后关闭时,相等的高度会发生碰撞,因此有时会改变AppBar.最好的解决方案是向remove any mask/additional effect that is made on 100人提供服务,而现在有elevation: 1人.因此,如果我增加AppBar的高度并隐藏所有效果,AppBar在任何情况下都将是真正透明的.谢谢你的帮助.

推荐答案

这个奇怪的 colored颜色 实际上是surfaceTintColor,这使得应用程序栏在使用material 3时是有色的.要删除它,请将其设置为透明:

AppBar(
  // ...
  surfaceTintColor: Colors.transparent,
),

要启用material 2中的立面阴影,请参见此帖子:

After upgrading to Flutter 3.16, the app bar, background color, button size, and spaces change

Flutter相关问答推荐

自动测试Flutter应用程序进行QA的最佳方法是什么?

关闭视频通话,相机仍在运行!(Flutter WebRTC)

使用自定义控制器将项插入到ListView中时行为不正确

CMakeLists.txt处的CMake错误:3(项目)找不到指定的Visual Studio实例

什么是dart :这只是dart ?

我怎样才能在Ffltter中显示html布局链接?

为什么我的图标的一半在定位小部件中消失了?

添加appBar时绘制的线条发生偏移 Flu

Flutter居中的SizedBox无法居中

在 Flutter 中,SpinEdit 叫什么?

更改 flutter listview 中的布局

Container 的 Flutter 背景图片不会出现

Flutter使Perspective Page View无限循环

Flutter Serverpod 在示例项目上返回 400 错误

Flutter:如何判断嵌套列表是否包含值

在 flutter 中使用 StreamBuilder 在文本字段中键入时显示过滤记录

我想在数组中添加项目

解密 Modulr 安全令牌

Flutter 评级栏包选中和未选中的容器

用于空值 FirebaseFirestore 的空值判断运算符