flutter-解决AppBar背景色为白色带滚动时不生效的bug

作为初学flutter的小白来说,今天在模仿小米商城app的首页appbar的时候,遇到一个奇怪的问题,就是修改AppBar的backgroundColor,在首页上拉滚动时,设置的白色背景色不生效,背景色变成不是淡灰色,其他深色不影响,唯独白色不行,flutter版本:3.16.8。

appbar背景色白色的bug

Dart 复制代码
AppBar(
...
//barOpacity是一个0~1.0的透明度的变量,视频中确实到了1的,不用怀疑
backgroundColor: Colors.white.withOpacity(controller.barOpacity.value), 
elevation: 0,
...)

仔细观察,AppBar的背景色一旦设置为白色且无透明度,下拉的时候就会把白色变成浅灰色,即使不加入渐变透明度的逻辑,固定写死也没用,但是改成其他颜色如绿色红色什么的,又好像没问题,到底是什么问题呢?

这让我不得不怀疑这个是不是受到主题风格的影响,于是我搞老搞去,修改了ThemeData,一脸懵逼就把问题解决了,如下代码:

Dart 复制代码
  theme: ThemeData(
            splashColor: Colors.transparent,
            highlightColor: Colors.transparent,
            //加入colorScheme既可以解决上面的问题
            colorScheme: const ColorScheme.light(
                primary: Colors.white,
                onPrimary: Colors.white,
                onBackground: Colors.white,
                secondary: Colors.white),
          ),
          debugShowCheckedModeBanner: false,
          title: "shop+demo",

如果对你有用,点个赞支持下吧

如果你还有更深的理解,也请回复下你的理解。

相关推荐
全栈派森21 小时前
初见 Dart:这门新语言如何让你的 App「动」起来?
android·flutter·ios
恋猫de小郭21 小时前
Dart 3.10 发布,快来看有什么更新吧
android·前端·flutter
恋猫de小郭1 天前
Flutter 3.38 发布,快来看看有什么更新吧
android·前端·flutter
lichong9512 天前
Android studio release 包打包配置 build.gradle
android·前端·ide·flutter·android studio·大前端·大前端++
旧时光_2 天前
第3章:基础组件 —— 3.6 进度指示器
flutter
旧时光_2 天前
第3章:基础组件 —— 3.3 图片及ICON
flutter
GISer_Jing2 天前
跨端框架对决:React Native vs Flutter深度对比
flutter·react native·react.js
猪哥帅过吴彦祖2 天前
Flutter 从入门到精通:深入 Navigator 2.0 - GoRouter 路由完全指南
android·flutter·ios
恋猫de小郭2 天前
来了解一下,为什么你的 Flutter WebView 在 iOS 26 上有点击问题?
android·前端·flutter
你听得到113 天前
肝了半个月,我用 Flutter 写了个功能强大的图片编辑器,告别image_cropper
android·前端·flutter