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

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

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

相关推荐
RaidenLiu10 小时前
从 Provider 迈向 Riverpod 3:核心架构与迁移指南
前端·flutter
叽哥10 小时前
Flutter面试:Dart基础2
flutter·面试·dart
tangweiguo0305198714 小时前
Android原生(Kotlin)与Flutter混合开发 - 设备控制与状态同步解决方案
android·flutter
江上清风山间明月1 天前
Flutter AlwaysScrollableScrollPhysics详解
flutter·滚动·scrollable·scrollphysics
普罗米拉稀1 天前
Flutter 复用艺术:Mixin 与 Abstract 的架构哲学与线性化解密
flutter·ios·面试
yangshuo12811 天前
AI编程工具对决:Kilo vs Augment 开发Flutter俄罗斯方块游戏实战对比
flutter·游戏·ai编程
tangweiguo030519872 天前
Flutter 自定义 Switch 切换组件完全指南
flutter
笔沫拾光2 天前
iOS 正式包签名指南
flutter·ios·ios签名
森之鸟2 天前
flutter项目适配鸿蒙
flutter·华为·harmonyos
傅里叶2 天前
Flutter在OrangePi 5 Plus上视频播放锁死问题
前端·flutter