我正在尝试使用透明的 AppBar 制作屏幕布局,该 AppBar 必须在其下方滚动内容。
问题是当内容滚动时,AppBar显示阴影,shadowColor,但它设置为透明颜色。
编辑:我注意到造成这种情况的原因是在我的应用程序主题中将 useMaterial3 设置为 true。
我使用的是 Flutter 3.0.2。
这是我的代码:
Stack(
fit: StackFit.expand,
children: [
//AuthBackground(),
Container(color: Colors.brown,),
Theme(
data: AppStyles.mainDarkTheme.copyWith(
textTheme: AppStyles.mainDarkTheme.textTheme.apply(
bodyColor: Colors.blue,
displayColor: Colors.blue,
)
),
child: Scaffold(
backgroundColor: Colors.transparent,
extendBodyBehindAppBar: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
elevation: 0.0,
bottomOpacity: 0.0,
),
body: _content(),
),
),
],
)
这里有一张图片,您可以在内容滚动时注意到 AppBar 上的阴影:
提前致谢!
我终于明白了。
我在这个帖子上回答了自己:
我也有同样的问题。
在我的例子中,我有一个带有透明背景的 AppBar 和一个脚手架 将extendBodyBehindAppBar 设置为true。
我尝试使用shadowColor和surfaceTintColor与Colors.transparent 值,但阴影仍然可见。
然后我注意到AppBar的scrolledUnderElevation属性。环境 将其设置为 0.0 就是解决方案。
设置海拔 = 0 对我有用
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
这是因为默认的海拔属性设置为appbar。所以简单的解决方案是设置高程属性。像下面这样
elevation: 0,
完成了。
您必须将 AppBar 的
scrolledUnderElevation
属性设置为 0
AppBar(
elevation: 0,
shadowColor: Colors.transparent,
backgroundColor: Colors.transparent,
scrolledUnderElevation: 0,
)
在应用栏中设置 scrolledUnderElevation = 0。