Skip to content

Commit 77b2c7a

Browse files
authored
doc: update docs/flutter.md (#828)
1 parent f510d35 commit 77b2c7a

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

docs/flutter.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,162 @@ PageView.builder(
892892
),
893893
),
894894
```
895+
### flutter动画组件
896+
897+
#### AnimatedContainer
898+
> 使用AnimatedContainer组件,配置curve曲线过渡和duration过渡时间
899+
900+
```dart
901+
class HomeState extends StatefulWidget{
902+
const HomeState({Key? key}) : super(key:key);
903+
904+
@override
905+
State<HomeState> createState()=>_HomeState();
906+
}
907+
908+
class _HomeState extends State<HomeState>{
909+
bool press = false; //设置动画触发的条件
910+
@override
911+
Widget build(BuildContext context) {
912+
return MaterialApp(
913+
home: Scaffold(
914+
floatingActionButton:FloatingActionButton(onPressed: (){
915+
setState(() {
916+
press = true; //点击FloatingActionButton进行动画效果
917+
});
918+
}
919+
,child: const Icon(Icons.add),) ,
920+
appBar: AppBar(
921+
title: const Text("测试"),
922+
),
923+
body: Center(
924+
child: AnimatedContainer(
925+
curve: Curves.ease, //曲线
926+
duration: const Duration(seconds: 1), //延时
927+
width: press ? 200 : 300,
928+
height: 200,
929+
color:Colors.yellow,
930+
transform: press ? Matrix4.translationValues(0, 0, 0) :
931+
Matrix4.translationValues(100, 100, 0)
932+
),
933+
)
934+
)
935+
);
936+
}
937+
}
938+
```
939+
940+
#### AnimatedPadding
941+
> 通过配置padding值的改变,引起组件的动画效果,同样支持curve和duration的配置
942+
943+
```dart
944+
class _HomeState extends State<HomeState>{
945+
bool press = false;
946+
@override
947+
Widget build(BuildContext context) {
948+
return MaterialApp(
949+
home: Scaffold(
950+
floatingActionButton:FloatingActionButton(onPressed: (){
951+
setState(() {
952+
press = true;
953+
});
954+
}
955+
,child: const Icon(Icons.add),) ,
956+
appBar: AppBar(
957+
title: const Text("测试"),
958+
),
959+
body: Center(
960+
child: AnimatedPadding(
961+
padding: EdgeInsets.fromLTRB(10, press ? 10 : 400, 0, 0), //配置边距值
962+
curve: Curves.ease, //曲线
963+
duration: const Duration(seconds: 1), //延时
964+
child: Container(
965+
width: 200,
966+
height: 200,
967+
color:Colors.yellow,
968+
),
969+
),
970+
)
971+
)
972+
);
973+
}
974+
}
975+
```
976+
977+
#### AnimatedAlign
978+
> 通过配置alignment值的改变,引起组件的动画效果,同样支持curve和duration的配置
979+
980+
```dart
981+
class _HomeState extends State<HomeState>{
982+
bool press = false;
983+
@override
984+
Widget build(BuildContext context) {
985+
return MaterialApp(
986+
home: Scaffold(
987+
floatingActionButton:FloatingActionButton(onPressed: (){
988+
setState(() {
989+
press = true;
990+
});
991+
}
992+
,child: const Icon(Icons.add),) ,
993+
appBar: AppBar(
994+
title: const Text("测试"),
995+
),
996+
body: Center(
997+
child: AnimatedAlign(
998+
alignment: press ? Alignment.center : Alignment.topCenter,
999+
curve: Curves.ease, //曲线
1000+
duration: const Duration(seconds: 1), //延时
1001+
child: Container(
1002+
width: 200,
1003+
height: 200,
1004+
color:Colors.yellow,
1005+
),
1006+
),
1007+
)
1008+
)
1009+
);
1010+
}
1011+
}
1012+
```
1013+
1014+
#### AnimatedOpacity
1015+
1016+
>通过配置opacity值的改变,引起组件的动画效果,同样支持curve和duration的配置
1017+
1018+
```dart
1019+
class _HomeState extends State<HomeState>{
1020+
bool press = false;
1021+
@override
1022+
Widget build(BuildContext context) {
1023+
return MaterialApp(
1024+
home: Scaffold(
1025+
floatingActionButton:FloatingActionButton(onPressed: (){
1026+
setState(() {
1027+
press = true;
1028+
});
1029+
}
1030+
,child: const Icon(Icons.add),) ,
1031+
appBar: AppBar(
1032+
title: const Text("测试"),
1033+
),
1034+
body: Center(
1035+
child: AnimatedOpacity(
1036+
opacity: press ? 1 : 0.1,
1037+
curve: Curves.ease, //曲线
1038+
duration: const Duration(seconds: 1), //延时
1039+
child: Container(
1040+
width: 200,
1041+
height: 200,
1042+
color:Colors.yellow,
1043+
),
1044+
),
1045+
)
1046+
)
1047+
);
1048+
}
1049+
}
1050+
```
8951051

8961052
另见
8971053
---

0 commit comments

Comments
 (0)