Skip to content

Commit 58d7c6f

Browse files
committed
feat:value change animtion
1 parent a72af9d commit 58d7c6f

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

lib/main.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import 'view/gestures.dart';
2828
import 'view/media_query.dart';
2929
import 'view/styled_text.dart';
3030
import 'view/animation/easeing.dart';
31+
import 'view/animation/valuechange.dart';
3132
// import 'package:flutter_examples_code/view/navigation_drawer/screens/home.dart';
3233
import 'package:flutter_examples_code/view/navigation_drawer/screens/account.dart';
3334
import 'package:flutter_examples_code/view/navigation_drawer/screens/setting.dart';
@@ -82,6 +83,7 @@ class MyApp extends StatelessWidget {
8283
"gestures_demo":(context)=> new GestureDemo(),
8384
"media_query": (context)=> new MediaQueryDemo(),
8485
"styled_text": (context)=> new StyleTextDemo(),
86+
"value_change_animation": (context)=> new ValueChangeAnimation(),
8587
},
8688
home: MyHomePage(title: '首页'),
8789
);
@@ -127,6 +129,7 @@ class _MyHomePageState extends State<MyHomePage> {
127129
"Media Query Demo": "media_query",
128130
"Styled Text Demo": "styled_text",
129131
"Easing Animation Demo": "easing_animation",
132+
"Value Change Animation": "value_change_animation",
130133
};
131134
Drawer getNavDrawer(BuildContext context){
132135
var headChild = new DrawerHeader(child:

lib/view/animation/valuechange.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter/widgets.dart';
3+
4+
class ValueChangeAnimation extends StatefulWidget {
5+
@override
6+
_ValueChangeAnimationState createState() => _ValueChangeAnimationState();
7+
}
8+
9+
class _ValueChangeAnimationState extends State<ValueChangeAnimation>
10+
with TickerProviderStateMixin {
11+
12+
AnimationController controller;
13+
Animation animation;
14+
@override
15+
void initState() {
16+
super.initState();
17+
controller = AnimationController(
18+
duration: new Duration(milliseconds: 1000), vsync: this);
19+
final Animation curve = CurvedAnimation(
20+
parent: controller, curve: Curves.easeOut);
21+
animation = IntTween(begin: 0, end: 10).animate(curve)
22+
..addStatusListener((status){
23+
if(status == AnimationStatus.completed){
24+
controller.reverse();
25+
}
26+
27+
if(status == AnimationStatus.dismissed){
28+
Navigator.pop(context);
29+
}
30+
});
31+
}
32+
@override
33+
Widget build(BuildContext context) {
34+
controller.forward();
35+
return AnimatedBuilder(
36+
animation: controller,
37+
builder: (BuildContext context, Widget child){
38+
return Scaffold(
39+
body: new Center(
40+
child: new Text(
41+
animation.value.toString(),
42+
style: TextStyle(fontSize: 48.0)
43+
),
44+
),
45+
);
46+
},
47+
);
48+
}
49+
50+
@override
51+
void dispose() {
52+
controller.dispose();
53+
super.dispose();
54+
}
55+
}

0 commit comments

Comments
 (0)