You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 06:14:55