Skip to content

Commit 9bbebf9

Browse files
authored
Merge pull request #37 from FlutterOpen/dev
Dev
2 parents a290d7c + 109f97d commit 9bbebf9

File tree

7 files changed

+259
-0
lines changed

7 files changed

+259
-0
lines changed

lib/const/page_item_const.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,19 @@ const PAGE_ITEMS = [
212212
"img": PageImage.FLUTTER_OPEN,
213213
"click": PageName.ANIM_POSITION_TRANS,
214214
},
215+
{
216+
"title": PageName.ANIM_ROTATION,
217+
"img": PageImage.FLUTTER_OPEN,
218+
"click": PageName.ANIM_ROTATION,
219+
},
220+
{
221+
"title": PageName.ANIM_DEFAULT_TEXT,
222+
"img": PageImage.FLUTTER_OPEN,
223+
"click": PageName.ANIM_DEFAULT_TEXT,
224+
},
225+
{
226+
"title": PageName.ANIM_LIST,
227+
"img": PageImage.FLUTTER_OPEN,
228+
"click": PageName.ANIM_LIST,
229+
},
215230
];

lib/const/page_name_const.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@ class PageName {
4747
static const ANIM_HERO = "HeroPage";
4848
static const ANIM_FADE_TRANS = "FadeTranstion";
4949
static const ANIM_POSITION_TRANS = "PositionTransition";
50+
static const ANIM_ROTATION = "RotationTransition";
51+
static const ANIM_DEFAULT_TEXT = "DefaultText";
52+
static const ANIM_LIST = "AnimationList";
5053
}

lib/main.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class FlutterOpenApp extends StatelessWidget {
6161
PageName.ANIM_HERO: (context) => HeroPage(),
6262
PageName.ANIM_FADE_TRANS: (context) => FadeTransitionPage(),
6363
PageName.ANIM_POSITION_TRANS: (context) => PositionTransitionPage(),
64+
PageName.ANIM_ROTATION: (context) => RotationPage(),
65+
PageName.ANIM_DEFAULT_TEXT: (context) => DefaultTextPage(),
66+
PageName.ANIM_LIST: (context) => AnimListPage(),
6467
},
6568
);
6669
}

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+
/// Email: niebin312@gmail.com
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(PageName.ANIM_LIST),
65+
),
66+
body: AnimatedList(
67+
key: _key,
68+
initialItemCount: list.length,
69+
itemBuilder: _itemBuilder,
70+
));
71+
}
72+
}

lib/page/anim/DefaultTextPage.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
///
2+
/// Created by NieBin on 2019/6/9
3+
/// Github: https://github.com/nb312
4+
/// Email: niebin312@gmail.com
5+
///
6+
import "package:flutter/material.dart";
7+
import 'package:flutter_widgets/const/_const.dart';
8+
9+
class DefaultTextPage extends StatefulWidget {
10+
@override
11+
DefaultState createState() => DefaultState();
12+
}
13+
14+
class DefaultState extends State<DefaultTextPage> {
15+
Color _color = RED_LIGHT;
16+
17+
Widget _defaultText() => Column(
18+
children: <Widget>[
19+
AnimatedDefaultTextStyle(
20+
child: Text(
21+
"Default Text",
22+
style: TextStyle(fontSize: 20),
23+
),
24+
style: TextStyle(color: _color),
25+
duration: Duration(seconds: 1),
26+
),
27+
FloatingActionButton(
28+
child: Text("Click"),
29+
onPressed: () {
30+
setState(() {
31+
if (_color == RED_LIGHT) {
32+
_color = BLUE_DEEP;
33+
} else {
34+
_color = RED_LIGHT;
35+
}
36+
});
37+
},
38+
)
39+
],
40+
);
41+
42+
@override
43+
Widget build(BuildContext context) {
44+
return Scaffold(
45+
appBar: AppBar(
46+
title: Text(PageName.ANIM_DEFAULT_TEXT),
47+
),
48+
body: Column(
49+
children: <Widget>[
50+
_defaultText(),
51+
],
52+
),
53+
);
54+
}
55+
}

lib/page/anim/RotationPage.dart

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
///
2+
/// Created by NieBin on 2019/6/9
3+
/// Github: https://github.com/nb312
4+
/// Email: niebin312@gmail.com
5+
///
6+
import 'package:flutter/material.dart';
7+
import 'package:flutter_widgets/const/_const.dart';
8+
import 'dart:math';
9+
10+
class RotationPage extends StatefulWidget {
11+
@override
12+
_RotationState createState() => _RotationState();
13+
}
14+
15+
class _RotationState extends State<RotationPage>
16+
with SingleTickerProviderStateMixin {
17+
AnimationController _controller;
18+
Animation<double> _rotationAnim;
19+
Animation<Offset> _offsetAnim;
20+
Animation<Decoration> _decorationAnim;
21+
22+
Widget _rotation() => RotationTransition(
23+
turns: _rotationAnim,
24+
alignment: Alignment.center,
25+
child: Text(
26+
"This is my first rotation transition.",
27+
style: TextStyle(color: BLUE_DEEP, fontSize: 10),
28+
),
29+
);
30+
31+
Widget _scale() => ScaleTransition(
32+
scale: _rotationAnim,
33+
child: Text("Scale transition."),
34+
);
35+
36+
Widget _slide() => SlideTransition(
37+
position: _offsetAnim,
38+
child: Text(
39+
"Offset",
40+
style: TextStyle(color: PURPLE),
41+
),
42+
);
43+
44+
Widget _sizeTrans() => SizeTransition(
45+
sizeFactor: _rotationAnim,
46+
child: Container(
47+
width: 100,
48+
height: 100,
49+
color: RED_LIGHT,
50+
),
51+
);
52+
53+
Widget _decoratedTrans() => DecoratedBoxTransition(
54+
decoration: _decorationAnim,
55+
child: Container(
56+
constraints: BoxConstraints.expand(height: 100, width: 200),
57+
child: InkWell(
58+
child: Center(
59+
child: Text("Click Me"),
60+
),
61+
onTap: () {
62+
_controller.reset();
63+
_controller.forward();
64+
},
65+
),
66+
));
67+
68+
@override
69+
void initState() {
70+
_controller = AnimationController(
71+
vsync: this,
72+
duration: Duration(seconds: 3),
73+
);
74+
CurvedAnimation _curve =
75+
CurvedAnimation(parent: _controller, curve: Curves.elasticIn);
76+
_rotationAnim = Tween(begin: 0.0, end: pi).animate(_curve);
77+
_offsetAnim =
78+
Tween(begin: Offset(0.0, 0.0), end: Offset(5.0, 1.0)).animate(_curve);
79+
_decorationAnim = DecorationTween(
80+
begin: ShapeDecoration(
81+
shape: StadiumBorder(
82+
side: BorderSide(color: RED_LIGHT, width: 1))),
83+
end: ShapeDecoration(
84+
shape: CircleBorder(side: BorderSide(color: BLUE, width: 4))))
85+
.animate(_curve);
86+
super.initState();
87+
}
88+
89+
@override
90+
Widget build(BuildContext context) {
91+
return Scaffold(
92+
appBar: AppBar(
93+
title: Text(PageName.ANIM_ROTATION),
94+
),
95+
body: Column(
96+
crossAxisAlignment: CrossAxisAlignment.center,
97+
mainAxisAlignment: MainAxisAlignment.center,
98+
children: <Widget>[
99+
_rotation(),
100+
_scale(),
101+
_slide(),
102+
_sizeTrans(),
103+
_decoratedTrans(),
104+
],
105+
),
106+
);
107+
}
108+
}

lib/page/anim/_anim.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ export 'AnimCrossFadePage.dart';
88
export 'HeroPage.dart';
99
export 'FadeTransitionPage.dart';
1010
export 'PositionTransitionPage.dart';
11+
export 'RotationPage.dart';
12+
export 'DefaultTextPage.dart';
13+
export 'AnimListPage.dart';

0 commit comments

Comments
 (0)