-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAnimations.dart
163 lines (152 loc) · 4.62 KB
/
Animations.dart
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
animate_icons: ^2.0.0
animations: ^2.0.0
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'container_transition.dart';
import 'fade_scale_transition.dart';
import 'fade_through_transition.dart';
import 'shared_axis_transition.dart';
void main() {
runApp(
MaterialApp(
theme: ThemeData.from(
colorScheme: const ColorScheme.light(),
).copyWith(
pageTransitionsTheme: const PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.android: ZoomPageTransitionsBuilder(),
},
),
),
home: _TransitionsHomePage(),
),
);
}
class _TransitionsHomePage extends StatefulWidget {
@override
_TransitionsHomePageState createState() => _TransitionsHomePageState();
}
class _TransitionsHomePageState extends State<_TransitionsHomePage> {
bool _slowAnimations = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Material Transitions')),
body: Column(
children: <Widget>[
Expanded(
child: ListView(
children: <Widget>[
_TransitionListTile(
title: 'Container transform',
subtitle: 'OpenContainer',
onTap: () {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (BuildContext context) {
return OpenContainerTransformDemo();
},
),
);
},
),
_TransitionListTile(
title: 'Shared axis',
subtitle: 'SharedAxisTransition',
onTap: () {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (BuildContext context) {
return SharedAxisTransitionDemo();
},
),
);
},
),
_TransitionListTile(
title: 'Fade through',
subtitle: 'FadeThroughTransition',
onTap: () {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (BuildContext context) {
return FadeThroughTransitionDemo();
},
),
);
},
),
_TransitionListTile(
title: 'Fade',
subtitle: 'FadeScaleTransition',
onTap: () {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (BuildContext context) {
return FadeScaleTransitionDemo();
},
),
);
},
),
],
),
),
const Divider(height: 0.0),
SafeArea(
child: SwitchListTile(
value: _slowAnimations,
onChanged: (bool value) async {
setState(() {
_slowAnimations = value;
});
// Wait until the Switch is done animating before actually slowing
// down time.
if (_slowAnimations) {
await Future<void>.delayed(const Duration(milliseconds: 300));
}
timeDilation = _slowAnimations ? 20.0 : 1.0;
},
title: const Text('Slow animations'),
),
),
],
),
);
}
}
class _TransitionListTile extends StatelessWidget {
const _TransitionListTile({
this.onTap,
required this.title,
required this.subtitle,
});
final GestureTapCallback? onTap;
final String title;
final String subtitle;
@override
Widget build(BuildContext context) {
return ListTile(
contentPadding: const EdgeInsets.symmetric(
horizontal: 15.0,
),
leading: Container(
width: 40.0,
height: 40.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
border: Border.all(
color: Colors.black54,
),
),
child: const Icon(
Icons.play_arrow,
size: 35,
),
),
onTap: onTap,
title: Text(title),
subtitle: Text(subtitle),
);
}
}