当前位置:网站首页>Flutter 使用 AnimatedSwitcher 做场景切换
Flutter 使用 AnimatedSwitcher 做场景切换
2022-07-17 18:19:00 【InfoQ】
前言
AnimatedSwitcher
AnimatedSwitcher 介绍
AnimatedSwitcherFadeTransitionAnimatedSwitcherconst AnimatedSwitcher({
Key? key,
this.child,
required this.duration,
this.reverseDuration,
this.switchInCurve = Curves.linear,
this.switchOutCurve = Curves.linear,
this.transitionBuilder = AnimatedSwitcher.defaultTransitionBuilder,
this.layoutBuilder = AnimatedSwitcher.defaultLayoutBuilder,
})
AnimatedSwitcherdurationreverseDuration:反向时长,也就是切换为旧组件的时长,不设置的话就和duration一致。
switchInCurve:切入动画曲线,也就是新组件切换进入的曲线;
switchOutCurve:切出动画曲线,也就是旧组件切换出去时的曲线;
transitionBuilder:切换转变动画构建,是一个函数,定义如下,可以用这个方法来构建自己的切换动效。
typedef AnimatedSwitcherTransitionBuilder = Widget Function(Widget child, Animation<double> animation);
layoutBuilder:可以设置新组件在组件树中的布局,也是一个函数:
typedef AnimatedSwitcherLayoutBuilder = Widget Function(Widget? currentChild, List<Widget> previousChildren);
defaultLayoutBuilderstatic Widget defaultLayoutBuilder(Widget? currentChild, List<Widget> previousChildren) {
return Stack(
children: <Widget>[
...previousChildren,
if (currentChild != null) currentChild,
],
alignment: Alignment.center,
);
}
AnimatedSwitcherAnimatedSwitcherWidgetcanUpdatestatic int _debugConcreteSubtype(Widget widget) {
return widget is StatefulWidget ? 1 :
widget is StatelessWidget ? 2 :
0;
}
KeyValueKey应用
SizeTransition class AnimatedSwitcherDemo extends StatefulWidget {
AnimatedSwitcherDemo({Key? key}) : super(key: key);
@override
_AnimatedSwitcherDemoState createState() => _AnimatedSwitcherDemoState();
}
class _AnimatedSwitcherDemoState extends State<AnimatedSwitcherDemo> {
Widget? _animatedWidget;
bool test = false;
@override
void initState() {
super.initState();
_animatedWidget = ClipOval(
child: Image.asset('images/beauty.jpeg'),
key: ValueKey(1),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('AnimatedSwticher'),
brightness: Brightness.dark,
backgroundColor: Colors.black,
),
backgroundColor: Colors.black,
body: Center(
child: Container(
padding: EdgeInsets.all(10.0),
child: AnimatedSwitcher(
child: _animatedWidget,
duration: const Duration(milliseconds: 1000),
transitionBuilder: (child, animation) {
return SizeTransition(
sizeFactor: animation,
child: child,
);
},
),
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.play_arrow),
onPressed: () {
setState(() {
test = !test;
_animatedWidget = test
? ClipOval(
child: Image.asset('images/beauty2.jpeg'),
key: ValueKey(2),
)
: ClipOval(
child: Image.asset('images/beauty.jpeg'),
key: ValueKey(1),
);
});
},
),
);
}
}
总结
AnimatedSwitcherAnimatedSwitcherKey
边栏推荐
- Advanced C language -- custom type: structure enumeration Union
- Panasonic A6 servo driver external absolute value grating ruler full closed loop parameter setting
- In depth sorting: summary of machine learning modeling and parameter adjustment methods
- Is it safe for Everbright futures to open an account online? Are there any account opening guidelines?
- Which domestic API tool is better? It turned out to be it
- npm err! [email protected] build: `umi build`
- [dynamic planning]dp27 jumping game (II) - medium
- 【错误记录/selectpicker】dropdown menu显示位置出现偏移
- codeforce:A. Difference Operations【数学思维】
- Audio common terminal anatomy - never make a mistake again
猜你喜欢
[email protected] @Zif67 nanomaterial"/>Nitrogen heterocyclic molecule modified uio-66-nh2 | polyethyleneimine modified uio-66-nh2| [email protected] @Zif67 nanomaterial

响应式织梦模板酒窖类网站

MatrixCube揭秘 101——MatrixCube的功能与架构
[email protected] )|Shell core"/>Cadmium sulfide supported mil-125 (TI) | streptavidin (SA) - zirconium porphyrin MOF composite (PCN- [email protected] )|Shell core

C语言进阶——字符函数和字符串函数

面试难题:分布式 Session 实现难点,这篇就够!

Interview difficulties: difficulties in implementing distributed session, this is enough!

Attachment handling of SAP Fiori
![Codeforce:g. good key, bad key [greed]](/img/5e/e34e549c15e2e495d3a274ea8e6f82.png)
Codeforce:g. good key, bad key [greed]

关于TCP/IP协议漏洞的安全措施
随机推荐
Galaxy Kirin V10 arm offline installation of portal
torch. utils. data. Dataloader description
【js逆向爬虫】-有道翻译js逆向实战
How to upgrade Flink job gracefully?
ArrayList underlying analysis
Array simulation queue
MOF customized materials | bimetallic CuNi MOF nano materials | core-shell structure [email protected] Nanocomposites | zif-8/ poly
[Yugong series] July 2022 go teaching course 012 forced type conversion
VMware imports ova/ovf virtual machine files
(pc+wap) dream weaving template clothing dress website
torch.utils.data.DataLoader说明
AI is the designer who knows you best? Let users generate digital clothing "by heart" Adidas ozworld
MatrixCube揭秘 101——MatrixCube的功能与架构
Minimum exchange times
【Pygame 学习笔记】7.事件
Chitosan coated pcn224 nanoparticles | metal organic skeleton fe-mil-88nh2 | nickel based MOF material (Ni MOF / NF)
Label ball problem
整理了一份通用的内存管理驱动代码
2.三数之和
jvm自学总结