Skip to content

Commit 27f21f4

Browse files
committed
add the AnimationList;
1 parent 7537fd4 commit 27f21f4

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

lib/const/page_item_const.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,9 @@ const PAGE_ITEMS = [
222222
"img": PageImage.FLUTTER_OPEN,
223223
"click": PageName.ANIM_DEFAULT_TEXT,
224224
},
225+
{
226+
"title": PageName.ANIM_LIST,
227+
"img": PageImage.FLUTTER_OPEN,
228+
"click": PageName.ANIM_LIST,
229+
},
225230
];

lib/const/page_name_const.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ class PageName {
4949
static const ANIM_POSITION_TRANS = "PositionTransition";
5050
static const ANIM_ROTATION = "RotationTransition";
5151
static const ANIM_DEFAULT_TEXT = "DefaultText";
52+
static const ANIM_LIST = "AnimationList";
5253
}

lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class FlutterOpenApp extends StatelessWidget {
6363
PageName.ANIM_POSITION_TRANS: (context) => PositionTransitionPage(),
6464
PageName.ANIM_ROTATION: (context) => RotationPage(),
6565
PageName.ANIM_DEFAULT_TEXT: (context) => DefaultTextPage(),
66+
PageName.ANIM_LIST: (context) => AnimListPage(),
6667
},
6768
);
6869
}

lib/page/anim/AnimListPage.dart

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
///
2+
/// Created by NieBin on 2019/6/9
3+
/// Github: https://github.com/nb312
4+
5+
///
6+
import "package:flutter/material.dart";
7+
import 'package:flutter_widgets/const/_const.dart';
8+
9+
class AnimListPage extends StatefulWidget {
10+
@override
11+
AnimListState createState() => AnimListState();
12+
}
13+
14+
List<String> list = [
15+
"Hello",
16+
"World",
17+
"AAAA",
18+
"BBBB",
19+
"CCCC",
20+
"DDDDD",
21+
"EEEE",
22+
"FFFF"
23+
];
24+
25+
class AnimListState extends State<AnimListPage>
26+
with SingleTickerProviderStateMixin {
27+
final _key = GlobalKey<AnimatedListState>();
28+
29+
Widget _itemBuilder(context, index, anim) => index == 0
30+
? FloatingActionButton(
31+
child: Text("Click"),
32+
onPressed: () {
33+
if (list.length > 20) {
34+
var s = list.removeAt(1);
35+
_key.currentState.removeItem(
36+
1,
37+
(context, anim) => ScaleTransition(
38+
scale: anim,
39+
child: Text(list[index]),
40+
),
41+
);
42+
} else {
43+
list.insert(1, "Hello");
44+
_key.currentState.insertItem(1);
45+
}
46+
},
47+
)
48+
: Container(
49+
constraints: BoxConstraints.expand(height: 40),
50+
child: ScaleTransition(
51+
scale: anim,
52+
child: Text(list[index]),
53+
));
54+
55+
@override
56+
void initState() {
57+
super.initState();
58+
}
59+
60+
@override
61+
Widget build(BuildContext context) {
62+
return Scaffold(
63+
appBar: AppBar(
64+
title: Text("Hello World"),
65+
),
66+
body: AnimatedList(
67+
key: _key,
68+
initialItemCount: list.length,
69+
itemBuilder: _itemBuilder,
70+
));
71+
}
72+
}

lib/page/anim/_anim.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ export 'FadeTransitionPage.dart';
1010
export 'PositionTransitionPage.dart';
1111
export 'RotationPage.dart';
1212
export 'DefaultTextPage.dart';
13+
export 'AnimListPage.dart';

0 commit comments

Comments
 (0)