forked from flutter/assets-for-api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation_status_value.dart
174 lines (158 loc) · 5.01 KB
/
animation_status_value.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
164
165
166
167
168
169
170
171
172
173
174
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:diagram_capture/diagram_capture.dart';
import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';
import 'diagram_step.dart';
final Duration _kTotalDuration = _kBreakDuration +
_kAnimationDuration +
_kBreakDuration +
_kAnimationDuration;
const Duration _kAnimationDuration = Duration(seconds: 3);
const Duration _kBreakDuration = Duration(seconds: 1, milliseconds: 500);
const double _kCurveAnimationFrameRate = 60.0;
class AnimationStatusValueDiagram extends StatefulWidget
implements DiagramMetadata {
const AnimationStatusValueDiagram();
@override
State<AnimationStatusValueDiagram> createState() =>
AnimationStatusValueDiagramState();
@override
String get name => 'animation_status_value';
}
class AnimationStatusValueDiagramState
extends State<AnimationStatusValueDiagram>
with TickerProviderStateMixin<AnimationStatusValueDiagram> {
late AnimationController _controller;
String _status = 'dismissed';
@override
void initState() {
super.initState();
_controller =
AnimationController(vsync: this, duration: _kAnimationDuration);
Timer(_kBreakDuration, () {
_controller.forward();
});
_controller
.addStatusListener((AnimationStatus status) {
switch (status) {
case AnimationStatus.dismissed:
_status = 'dismissed';
break;
case AnimationStatus.forward:
_status = 'forward';
break;
case AnimationStatus.reverse:
_status = 'reverse';
break;
case AnimationStatus.completed:
_status = 'completed';
Timer(_kBreakDuration, () {
_controller.reverse();
});
break;
}
});
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container(
height: 100,
width: 420,
color: Colors.white,
child: Center(
child: AnimatedBuilder(
animation: _controller,
builder: (BuildContext context, Widget? _) {
return Table(
columnWidths: const <int, TableColumnWidth>{
0: FixedColumnWidth(180),
1: FixedColumnWidth(120),
2: FixedColumnWidth(100),
},
children: <TableRow>[
TableRow(
children: <Widget>[
Center(
child: Text(
_status,
style: const TextStyle(fontSize: 26),
),
),
Center(
child: Text(
_controller.value.toStringAsFixed(2),
style: const TextStyle(fontSize: 26),
),
),
Center(
child: Opacity(
opacity: _controller.value,
child: Container(
height: 35,
width: 35,
color: Colors.orange,
),
),
),
],
),
const TableRow(
children: <Widget>[
Center(
child: Padding(
padding: EdgeInsets.all(5),
child: Text('Animation.status'),
),
),
Center(
child: Padding(
padding: EdgeInsets.all(5),
child: Text('Animation.value'),
),
),
Center(
child: Padding(
padding: EdgeInsets.all(5),
child: Text('as Opacity'),
),
),
],
),
],
);
},
),
),
);
}
}
class AnimationStatusValueDiagramStep
extends DiagramStep<AnimationStatusValueDiagram> {
AnimationStatusValueDiagramStep(DiagramController controller)
: super(controller);
@override
final String category = 'animation';
@override
Future<List<AnimationStatusValueDiagram>> get diagrams async => const <AnimationStatusValueDiagram>[
AnimationStatusValueDiagram(),
];
@override
Future<File> generateDiagram(AnimationStatusValueDiagram diagram) async {
controller.builder = (BuildContext context) => diagram;
return await controller.drawAnimatedDiagramToFiles(
end: _kTotalDuration,
frameRate: _kCurveAnimationFrameRate,
name: diagram.name,
category: category,
);
}
}