flutter - 颤振:如何通过渐变动画更改容器颜色
问题描述
所以我想慢慢改变我的 AppColor。这是整个代码
body: DefaultTabController(
length: _tabs.length, // This is the number of tabs.
child: NestedScrollView(
controller: scrollController,
headerSliverBuilder: (context, bool innerBoxIsScrolled) {
return <Widget>[
SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverSafeArea(
top: false,
sliver: SliverAppBar(
pinned: true,
titleSpacing: 0.0,
elevation: 0.0,
flexibleSpace: Container(
color: innerBoxIsScrolled ? ColorTheme().white : ColorTheme().homeSkyblue,
),
我想在下面更改此代码
flexibleSpace: Container(
color: innerBoxIsScrolled ? ColorTheme().white : ColorTheme().homeSkyblue,
),
好吧,我希望我的 Appbars 改变颜色,慢慢地从 homeSkyblue 到 white 。但现在它可以立即工作。所以我尝试使用 offset 或 animatedController 但它们都没有工作......
有没有人有一些好的解决方案或小部件?
解决方案
您可以使用“AnimatedContainer”,它类似于 Container,但您应该使用持续时间。你可以看看这个文档:https ://api.flutter.dev/flutter/widgets/AnimatedContainer-class.html
所以你的代码将变成这样:
flexibleSpace: AnimatedContainer(
duration: Duration(seconds: 2),
color: innerBoxIsScrolled ? ColorTheme().white : ColorTheme().homeSkyblue,
),
推荐阅读
- r - 如何在句子中添加删除的空格?
- python - Pyserial 可以在命令行中从 arduino 读取数据,但 python 文件不能
- java - 求地图到地图转换的优化建议
- reactjs - 在地图中间过滤>0时如何避免显示错误
- c# - 为什么结合 Task.Run 和 plinq 这么慢?
- postman - 基于来自 arrayElement 的响应的 JSON 验证检查
- c# - 为什么单元测试 Assert.AreEqual() 方法不会在自定义类中选择我自己的 Equals() 方法
- jquery - Jquery UI Autocomplete Custom HTML (TypeError: t.item is undefined)
- react-native - 如何避免日期字符串之间的换行?[反应原生]
- android - Android Api (Okhttps) 未在 android 9(pie) 及更高版本中调用