Skip to content

Commit c226dd1

Browse files
committed
Merge branch 'lhr', remote-tracking branch 'origin' into test
2 parents 8957bec + e72cc6f commit c226dd1

File tree

11 files changed

+280
-61
lines changed

11 files changed

+280
-61
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## **AnimationController**
2+
3+
>
4+
AnimationController是一个特殊的Animation对象
5+
* 默认情况下,AnimationController在给定的时间段内会线性的生成从0.0到1.0的数字
6+
* 创建一个AnimationController时需要传递一个vsync参数,存在vsync时会防止屏幕外动画(动画的UI不在当前屏幕时)消耗不必要的资源,通过将SingleTickerProviderStateMixin添加到类定义中
7+
* 实例化一个AnimationController不会启动它运行,可以通过 .forward()方法启动动画
8+
* AnimationController的addListener方法可以监听动画每一帧
9+
* AnimationController的addStatusListener方法可以监听动画的状态
10+
11+
12+
### 构造方法
13+
``` dart
14+
AnimationController({
15+
double value,
16+
this.duration,
17+
this.debugLabel,
18+
this.lowerBound = 0.0,
19+
this.upperBound = 1.0,
20+
this.animationBehavior = AnimationBehavior.normal,
21+
@required TickerProvider vsync,
22+
})
23+
```
24+
25+
### 属性介绍
26+
* value: 动画值
27+
* lowerBound: 动画最小值
28+
* upperBound: 动画最大值
29+
* duration: 动画持续时间
30+
* vsync: vsync对象会绑定动画的定时器到一个可视的widget,所以当widget不显示时,动画定时器将会暂停,当widget再次显示时,动画定时器重新恢复执行,这样就可以避免动画相关UI不在当前屏幕时消耗资源。 如果要使用自定义的State对象作为vsync时,请包含TickerProviderStateMixin,因为是当前Widget使用动画,所以一般绑定值为 this

docs/widget/common/text/index.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
1-
## ****
1+
## **Text**
2+
3+
>
4+
单一样式的文本,文本可多行显示,也可能全部显示在同一行上
5+
* 默认会继承最接近控件的DefaultTextStyle
6+
* 最基本的文本组件
7+
8+
### 构造方法
9+
10+
``` dart
11+
Text(this.data, {
12+
Key key,
13+
this.style,
14+
this.textAlign,
15+
this.textDirection,
16+
this.locale,
17+
this.softWrap,
18+
this.overflow,
19+
this.textScaleFactor,
20+
this.maxLines,
21+
this.semanticsLabel,
22+
})
23+
```
24+
25+
### 属性介绍
26+
* data: Text显示的文本,必选参数
27+
* style: 文本样式
28+
* textAlign: 文本对齐方式
29+
* textDirection: 文本显示方向
30+
* maxLines: 文本最多显示几行
31+
* overflow: 文本溢出显示的截断方式
32+
* textScaleFactor: 文本缩放比例
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import 'package:flutter/material.dart';
2+
3+
class Index extends StatelessWidget {
4+
@override
5+
Widget build(BuildContext context) {
6+
return Scaffold(
7+
appBar: AppBar(
8+
title: Text('AnimationController'),
9+
),
10+
body: AnimationDemo()
11+
);
12+
}
13+
}
14+
15+
class AnimationDemo extends StatefulWidget {
16+
@override
17+
_AnimationDemoState createState() => _AnimationDemoState();
18+
}
19+
20+
class _AnimationDemoState extends State<AnimationDemo>
21+
with TickerProviderStateMixin{
22+
23+
AnimationController animationDemoController;
24+
Animation animation;
25+
Animation animationColor;
26+
CurvedAnimation curve;
27+
28+
@override
29+
void initState() {
30+
// TODO: implement initState
31+
super.initState();
32+
animationDemoController = AnimationController(
33+
// value: 32,
34+
// lowerBound: 32,
35+
// upperBound: 100,
36+
duration: Duration(milliseconds: 2500),
37+
vsync: this
38+
);
39+
40+
41+
curve = CurvedAnimation(parent: animationDemoController, curve: Curves.bounceOut);
42+
43+
animation = Tween(begin: 32.0, end: 100.0).animate(curve);
44+
animationColor = ColorTween(begin: Colors.pinkAccent, end: Colors.red).animate(curve);
45+
46+
animationDemoController.addListener(() {
47+
print('当前动画值:${animationDemoController.value}');
48+
});
49+
animationDemoController.addStatusListener((AnimationStatus status) {
50+
print('当前动画状态:${status}');
51+
});
52+
animationDemoController.forward();
53+
}
54+
55+
@override
56+
void dispose() {
57+
// TODO: implement dispose
58+
super.dispose();
59+
animationDemoController.dispose();
60+
}
61+
62+
63+
@override
64+
Widget build(BuildContext context) {
65+
return Center(
66+
child: AnimatedHeart(
67+
animations: [
68+
animation,
69+
animationColor
70+
],
71+
controller: animationDemoController,
72+
),
73+
);
74+
}
75+
}
76+
77+
78+
class AnimatedHeart extends AnimatedWidget {
79+
final List animations;
80+
final AnimationController controller;
81+
82+
AnimatedHeart({
83+
this.animations,
84+
this.controller
85+
}):super(listenable: controller);
86+
87+
@override
88+
Widget build(BuildContext context) {
89+
return IconButton(
90+
icon: Icon(Icons.favorite),
91+
iconSize: animations[0].value,
92+
color: animations[1].value,
93+
onPressed: (){
94+
switch (controller.status) {
95+
case AnimationStatus.completed:
96+
controller.reverse();
97+
break;
98+
default:
99+
controller.forward();
100+
}
101+
},
102+
);
103+
}
104+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:efox_flutter/components/widgetComp.dart' as WidgetComp;
3+
import 'demo.dart' as Demo;
4+
5+
class Index extends StatefulWidget {
6+
static String title = 'AnimationController';
7+
static String mdUrl = 'docs/widget/animate/animationcontroller/index.md';
8+
static String originCodeUrl = 'https://docs.flutter.io/flutter/animation/AnimationController-class.html';
9+
10+
@override
11+
_IndexState createState() => new _IndexState();
12+
}
13+
14+
class _IndexState extends State<Index> {
15+
@override
16+
Widget build(BuildContext context) {
17+
return WidgetComp.Index(
18+
title: Index.title,
19+
originCodeUrl: Index.originCodeUrl,
20+
mdUrl: Index.mdUrl,
21+
demoChild: [
22+
Demo.Index(),
23+
],
24+
);
25+
}
26+
}

lib/widget/animate/index.dart

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:efox_flutter/store/objects/widget_info.dart';
2+
import 'animationcontroller/index.dart' as AnimationController;
23
import 'animatedopacity/index.dart' as animatedopacity;
34
import 'animatedphysicalmodel/index.dart' as animatedphysicalmodel;
45
import 'animatedpositioned/index.dart' as animatedpositioned;
@@ -23,104 +24,109 @@ import 'animatedbuilder/index.dart' as animatedbuilder;
2324
const nameSpaces = '/animate_';
2425

2526
List widgets = [
27+
ItemInfo(
28+
widget: AnimationController.Index(),
29+
code: 57685, // gesture
30+
title: AnimationController.Index.title,
31+
),
2632
ItemInfo(
2733
widget: animatedbuilder.Index(),
28-
code: 58348, // grid_on
34+
code: 58295, // color_lens
2935
title: animatedbuilder.Index.title,
3036
),
3137
ItemInfo(
3238
widget: animatedcontainer.Index(),
33-
code: 58348, // grid_on
39+
code: 58297, // compare
3440
title: animatedcontainer.Index.title,
3541
),
3642
ItemInfo(
3743
widget: animatedcrossfade.Index(),
38-
code: 58348, // grid_on
44+
code: 58936, // confirmation_number
3945
title: animatedcrossfade.Index.title,
4046
),
4147
ItemInfo(
4248
widget: animateddefaulttextstyle.Index(),
43-
code: 58348, // grid_on
49+
code: 57678, // content_cut
4450
title: animateddefaulttextstyle.Index.title,
4551
),
4652
ItemInfo(
4753
widget: animatedliststate.Index(),
48-
code: 58348, // grid_on
54+
code: 59660, // copyright
4955
title: animatedliststate.Index.title,
5056
),
5157
ItemInfo(
5258
widget: animatedmodalbarrier.Index(),
53-
code: 58348, // grid_on
59+
code: 58060, // create_new_folder
5460
title: animatedmodalbarrier.Index.title,
5561
),
5662
ItemInfo(
5763
widget: slidetransition.Index(),
58-
code: 58348, // grid_on
64+
code: 59505, // dashboard
5965
title: slidetransition.Index.title,
6066
),
6167
ItemInfo(
6268
widget: sizetransition.Index(),
63-
code: 58348, // grid_on
69+
code: 58742, // departure_board
6470
title: sizetransition.Index.title,
6571
),
6672
ItemInfo(
6773
widget: scaletransition.Index(),
68-
code: 58348, // grid_on
74+
code: 58125, // developer_board
6975
title: scaletransition.Index.title,
7076
),
7177
ItemInfo(
7278
widget: rotationtransition.Index(),
73-
code: 58348, // grid_on
79+
code: 57776, // developer_mode
7480
title: rotationtransition.Index.title,
7581
),
7682
ItemInfo(
7783
widget: positionedtransition.Index(),
78-
code: 58348, // grid_on
84+
code: 58165, // device_hub
7985
title: positionedtransition.Index.title,
8086
),
8187
ItemInfo(
8288
widget: hero.Index(),
83-
code: 58348, // grid_on
89+
code: 58167, // devices_other
8490
title: hero.Index.title,
8591
),
8692
ItemInfo(
8793
widget: fadetransition.Index(),
88-
code: 58348, // grid_on
94+
code: 58674, // directions_boat
8995
title: fadetransition.Index.title,
9096
),
9197
ItemInfo(
9298
widget: decoratedboxtransition.Index(),
93-
code: 58348, // grid_on
99+
code: 58896, // disc_full
94100
title: decoratedboxtransition.Index.title,
95101
),
96102
ItemInfo(
97103
widget: animatedwidgetbasestate.Index(),
98-
code: 58348, // grid_on
104+
code: 59509, // dns
99105
title: animatedwidgetbasestate.Index.title,
100106
),
101107
ItemInfo(
102108
widget: animatedwidget.Index(),
103-
code: 58348, // grid_on
109+
code: 59672, // donut_small
104110
title: animatedwidget.Index.title,
105111
),
106112
ItemInfo(
107113
widget: animatedsize.Index(),
108-
code: 58348, // grid_on
114+
code: 57778, // dvr
109115
title: animatedsize.Index.title,
110116
),
111117
ItemInfo(
112118
widget: animatedpositioned.Index(),
113-
code: 58348, // grid_on
119+
code: 57373, // equalizer
114120
title: animatedpositioned.Index.title,
115121
),
116122
ItemInfo(
117123
widget: animatedphysicalmodel.Index(),
118-
code: 58348, // grid_on
124+
code: 59686, // euro_symbol
119125
title: animatedphysicalmodel.Index.title,
120126
),
121127
ItemInfo(
122128
widget: animatedopacity.Index(),
123-
code: 58348, // grid_on
129+
code: 58733, // ev_station
124130
title: animatedopacity.Index.title,
125131
),
126132
];

0 commit comments

Comments
 (0)