Flutter升级Material 3后AppBar滚动时出现异常背景色问题
解决Material3滚动时AppBar背景异常的方案
要让AppBar始终保持白色,可通过以下几种方式处理:
- 设置surfaceTintColor为透明
Material3中AppBar滚动到内容下方时会显示surface tint颜色,将其设为透明即可消除异常背景:
AppBar( backgroundColor: Colors.white, surfaceTintColor: Colors.transparent, title: const Text("页面标题"), )
- 固定滚动时的elevation
若异常颜色来自滚动时的阴影变化,可设置scrolledUnderElevation为0,禁用滚动时的elevation调整:
AppBar( backgroundColor: Colors.white, scrolledUnderElevation: 0.0, title: const Text("页面标题"), )
- 全局禁用滚动背景效果
如果需要整个应用的AppBar都保持该行为,可自定义ScrollBehavior并全局应用:
class NoScrollUnderBehavior extends ScrollBehavior { @override double get scrollUnderElevation => 0.0; } // 在MaterialApp中配置 MaterialApp( scrollBehavior: NoScrollUnderBehavior(), home: const YourHomePage(), )
内容的提问来源于stack exchange,提问作者Carlos
相关产品推荐
相关产品推荐

