@@ -41,6 +41,7 @@ $ sudo softwareupdate --install-rosetta --agree-to-license
41
41
< ! --rehype:className=style-timeline-->
42
42
43
43
# ## Windows 操作系统上安装和配置
44
+ < ! --rehype:wrap-class=col-span-2-->
44
45
45
46
> 完整教程请参阅 Flutter 中文社区的 [安装和环境配置](https://docs.flutter.cn/get-started/install)
46
47
@@ -783,7 +784,8 @@ ListView.separated(
783
784
```
784
785
785
786
### GridView
786
- <!-- rehype:wrap-class=col-span-2-->
787
+ <!-- rehype:wrap-class=col-span-2 row-span-2-->
788
+
787
789
` GridView ` 可将元素显示为二维网格状的列表组件,并支持主轴方向滚动。
788
790
使用GridView() 构造函数,需要传入gridDelegate和children。Flutter中已经提供了两种实现方式,分别是:
789
791
@@ -892,14 +894,17 @@ PageView.builder(
892
894
),
893
895
),
894
896
```
895
- ## flutter动画组件
897
+
898
+ Flutter 动画组件
899
+ ---
896
900
897
901
### 1.隐式动画
898
902
899
- > 在动画组件内,直接配置curve和duration属性
903
+ 在动画组件内,直接配置curve和duration属性
900
904
901
905
#### AnimatedContainer
902
- > 使用AnimatedContainer组件,配置curve曲线过渡和duration过渡时间
906
+
907
+ 使用AnimatedContainer组件,配置curve曲线过渡和duration过渡时间
903
908
904
909
``` dart
905
910
class HomeState extends StatefulWidget{
@@ -942,7 +947,8 @@ class _HomeState extends State<HomeState>{
942
947
```
943
948
944
949
#### AnimatedPadding
945
- > 通过配置padding值的改变,引起组件的移动动画效果,同样支持curve和duration的配置
950
+
951
+ 通过配置padding值的改变,引起组件的移动动画效果,同样支持curve和duration的配置
946
952
947
953
``` dart
948
954
class _HomeState extends State<HomeState>{
@@ -979,7 +985,8 @@ class _HomeState extends State<HomeState>{
979
985
```
980
986
981
987
#### AnimatedAlign
982
- > 通过配置alignment值的改变,引起组件的对齐动画效果,同样支持curve和duration的配置
988
+
989
+ 通过配置alignment值的改变,引起组件的对齐动画效果,同样支持curve和duration的配置
983
990
984
991
``` dart
985
992
class _HomeState extends State<HomeState>{
@@ -1017,7 +1024,7 @@ class _HomeState extends State<HomeState>{
1017
1024
1018
1025
#### AnimatedOpacity
1019
1026
1020
- > 通过配置opacity值的改变,引起组件的透明度变化动画效果,同样支持curve和duration的配置
1027
+ 通过配置opacity值的改变,引起组件的透明度变化动画效果,同样支持curve和duration的配置
1021
1028
1022
1029
``` dart
1023
1030
class _HomeState extends State<HomeState>{
@@ -1052,9 +1059,10 @@ class _HomeState extends State<HomeState>{
1052
1059
}
1053
1060
}
1054
1061
```
1062
+
1055
1063
#### AnimatedPositioned
1056
1064
1057
- > 通过配置top,left,right,bottom值的改变,引起组件的距离变化动画效果,同样支持curve和duration的配置
1065
+ 通过配置top,left,right,bottom值的改变,引起组件的距离变化动画效果,同样支持curve和duration的配置
1058
1066
1059
1067
``` dart
1060
1068
class _HomeState extends State<HomeState>{
@@ -1094,12 +1102,13 @@ class _HomeState extends State<HomeState>{
1094
1102
```
1095
1103
1096
1104
### 2.显示动画
1105
+ <!-- rehype:wrap-class=col-span-2-->
1097
1106
1098
- > 使用显示动画,定义AnimationController,在组件上with SingleTickerProviderStateMixin
1107
+ 使用显示动画时,定义 ` AnimationController ` ,并在组件中使用 ` SingleTickerProviderStateMixin ` 。
1099
1108
1100
1109
#### RotationTransition
1101
1110
1102
- > RotationTransition实现旋转动画,turns为AnimationController,可以在initState初始化的时候设置vsync,duration来让程序和手机的刷新频率统一,使用..联级操作调用repeat函数让动画重复运动
1111
+ ` RotationTransition ` 实现旋转动画, ` turns ` 为 ` AnimationController ` 。在 ` initState ` 中设置 ` vsync ` 和 ` duration ` ,使用 ` ..repeat() ` 实现动画循环。
1103
1112
1104
1113
``` dart
1105
1114
class _Boxed extends State<Boxed> with SingleTickerProviderStateMixin{
@@ -1111,7 +1120,7 @@ class _Boxed extends State<Boxed> with SingleTickerProviderStateMixin{
1111
1120
_controller = AnimationController(
1112
1121
vsync: this,
1113
1122
duration: const Duration(seconds: 1)
1114
- )..repeat(); //让程序和手机的刷新频率统一
1123
+ )..repeat(); // 让程序和手机的刷新频率统一
1115
1124
}
1116
1125
1117
1126
@override
@@ -1129,18 +1138,6 @@ class _Boxed extends State<Boxed> with SingleTickerProviderStateMixin{
1129
1138
1130
1139
#### AnimationController
1131
1140
1132
- > controller的播放方式
1133
- >
1134
- > repeat 重复
1135
- >
1136
- > forward 播放一次
1137
- >
1138
- > reverse 倒序播放
1139
- >
1140
- > stop 停止
1141
- >
1142
- > reset 重置
1143
-
1144
1141
``` dart
1145
1142
class _HomeState extends State<HomeState> with SingleTickerProviderStateMixin {
1146
1143
@@ -1149,37 +1146,38 @@ class _HomeState extends State<HomeState> with SingleTickerProviderStateMixin {
1149
1146
@override
1150
1147
void initState() {
1151
1148
super.initState();
1152
- _controller =
1153
- AnimationController(vsync: this, duration: const Duration(seconds: 1));//让程序和手机的刷新频率统一
1149
+ // 让程序和手机的刷新频率统一
1150
+ _controller = AnimationController(vsync: this, duration: const Duration(seconds: 1));
1154
1151
}
1155
1152
1156
1153
@override
1157
1154
Widget build(BuildContext context) {
1158
1155
return MaterialApp(
1159
1156
home: Scaffold(
1160
- floatingActionButton:FloatingActionButton(onPressed: (){
1157
+ floatingActionButton:FloatingActionButton(onPressed: () {
1161
1158
_controller.repeat(); //重复播放
1162
1159
},child:const Icon(Icons.add),) ,
1163
1160
appBar: AppBar(
1164
1161
title: const Text("测试"),
1165
1162
),
1166
1163
body: Center(
1167
1164
child: Column(
1168
- children: [RotationTransition(
1169
- turns: _controller,
1170
- child: const FlutterLogo(size: 60),
1171
- ),
1172
- ElevatedButton(onPressed: (){
1173
- _controller.forward(); //播放一次
1174
- }, child:const Icon(Icons.refresh)),
1165
+ children: [
1166
+ RotationTransition(
1167
+ turns: _controller,
1168
+ child: const FlutterLogo(size: 60),
1169
+ ),
1175
1170
ElevatedButton(onPressed: (){
1176
- _controller.reverse (); //倒序播放
1171
+ _controller.forward (); // 👈 播放一次
1177
1172
}, child:const Icon(Icons.refresh)),
1178
1173
ElevatedButton(onPressed: (){
1179
- _controller.stop (); //停止
1174
+ _controller.reverse (); // 👈 倒序播放
1180
1175
}, child:const Icon(Icons.refresh)),
1181
1176
ElevatedButton(onPressed: (){
1182
- _controller.reset(); //重置
1177
+ _controller.stop(); // 👈 停止
1178
+ }, child:const Icon(Icons.refresh)),
1179
+ ElevatedButton(onPressed: (){
1180
+ _controller.reset(); // 👈 重置
1183
1181
}, child:const Icon(Icons.refresh)),
1184
1182
]
1185
1183
)
@@ -1192,7 +1190,7 @@ class _HomeState extends State<HomeState> with SingleTickerProviderStateMixin {
1192
1190
1193
1191
#### FadeTransition
1194
1192
1195
- > RotationTransition实现透明度变化动画,opacity为AnimationController,可以在initState初始化的时候设置vsync,duration来让程序和手机的刷新频率统一,同时controller为0-1的值,因此opacity会发生从透明到实体的过程,如果要实现实体逐渐到透明可以使用reverse()倒序播放
1193
+ ` FadeTransition ` 实现透明度变化, ` opacity ` 为 ` AnimationController ` 。可以通过 ` reverse() ` 实现从实体逐渐变透明。
1196
1194
1197
1195
``` dart
1198
1196
class _HomeState extends State<HomeState> with SingleTickerProviderStateMixin {
@@ -1202,8 +1200,8 @@ class _HomeState extends State<HomeState> with SingleTickerProviderStateMixin {
1202
1200
@override
1203
1201
void initState() {
1204
1202
super.initState();
1205
- _controller =
1206
- AnimationController(vsync: this, duration: const Duration(seconds: 1));//让程序和手机的刷新频率统一
1203
+ //让程序和手机的刷新频率统一
1204
+ _controller = AnimationController(vsync: this, duration: const Duration(seconds: 1));
1207
1205
}
1208
1206
1209
1207
@override
@@ -1227,22 +1225,20 @@ class _HomeState extends State<HomeState> with SingleTickerProviderStateMixin {
1227
1225
}
1228
1226
```
1229
1227
1230
- > 也可以通过lowerBound和upperBound来配置controller的最低和最高值
1228
+ 也可以通过 lowerBound 和 upperBound 来配置 controller 的最低和最高值
1231
1229
1232
1230
#### ScaleTransition
1233
1231
1234
- > ScaleTransition实现放大缩小动画,scale为AnimationController,可以在initState初始化的时候设置vsync,duration来让程序和手机的刷新频率统一,同时controller为0-1的值,因此scale会发生从小到大的过程,如果要实现大逐渐到小可以使用reverse()倒序播放
1232
+ ` ScaleTransition ` 实现缩放动画, ` scale ` 为 ` AnimationController ` ,可以通过 ` reverse() ` 实现从大到小的动画效果。
1235
1233
1236
1234
``` dart
1237
1235
class _HomeState extends State<HomeState> with SingleTickerProviderStateMixin {
1238
-
1239
1236
late AnimationController _controller;
1240
-
1241
1237
@override
1242
1238
void initState() {
1243
1239
super.initState();
1244
- _controller =
1245
- AnimationController(vsync: this, duration: const Duration(seconds: 1));//让程序和手机的刷新频率统一
1240
+ // 让程序和手机的刷新频率统一
1241
+ _controller = AnimationController(vsync: this, duration: const Duration(seconds: 1));
1246
1242
}
1247
1243
1248
1244
@override
0 commit comments