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",

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

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

相关推荐
TT_Close14 小时前
🐟 发布中心进度同步:8 个商店的上传功能开发完毕,正抓紧测试
flutter·npm·visual studio code
RaidenLiu15 小时前
Flutter Platform Channel 底层架构解析 —— 从 BinaryMessenger 到跨平台消息通信机制
前端·flutter·前端框架
鹏多多21 小时前
Flutter使用screenshot进行截屏和截长图以及分享保存的全流程指南
android·前端·flutter
恋猫de小郭21 小时前
什么 AI 写 Android 最好用?官方做了一个基准测试排名
android·前端·flutter
勤劳打代码2 天前
Flutter 架构日记 — 状态管理
flutter·架构·前端框架
比特鹰4 天前
手把手带你用Flutter手搓人生K线
前端·javascript·flutter
火柴就是我4 天前
Flutter限制输入框只能输入中文,iOS拼音打不出来?
flutter
TT_Close4 天前
【Flutter×鸿蒙】debug 包也要签名,这点和 Android 差远了
android·flutter·harmonyos
TT_Close4 天前
【Flutter×鸿蒙】FVM 不认鸿蒙 SDK?4步手动塞进去
flutter·swift·harmonyos
TT_Close5 天前
【Flutter×鸿蒙】一个"插队"技巧,解决90%的 command not found
flutter·harmonyos