15-AnimatedDefaultTextStyle

Catalogue

效果:

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class GMExampleAnimatedDefaultTextStyleTest extends StatefulWidget {
GMExampleAnimatedDefaultTextStyleTest({Key key}) : super(key: key);

@override
_GMExampleAnimatedDefaultTextStyleTestState createState() =>
_GMExampleAnimatedDefaultTextStyleTestState();
}

class _GMExampleAnimatedDefaultTextStyleTestState
extends State<GMExampleAnimatedDefaultTextStyleTest>
with SingleTickerProviderStateMixin {
TextStyle _style;

@override
void initState() {
_style = TextStyle(color: Colors.blue, fontSize: 14);
super.initState();
}

@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
SizedBox(
height: 200,
),
AnimatedDefaultTextStyle(
style: _style,
duration: Duration(seconds: 2),
child: Text("老孟"),
),
SizedBox(
height: 100,
),
RaisedButton(
onPressed: () {
setState(() {
_style = TextStyle(color: Colors.red, fontSize: 24);
});
},
),
],
);
}
}