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
// Copyright 2016 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 'package:flutter_test/flutter_test.dart';
import 'package:flutter/animation.dart';
import 'package:flutter/widgets.dart';
class BogusCurve extends Curve {
@override
double transform(double t) => 100.0;
}
void main() {
setUp(() {
WidgetsFlutterBinding.ensureInitialized();
WidgetsBinding.instance.resetEpoch();
});
test('toString control test', () {
expect(kAlwaysCompleteAnimation, hasOneLineDescription);
expect(kAlwaysDismissedAnimation, hasOneLineDescription);
expect(const AlwaysStoppedAnimation<double>(0.5), hasOneLineDescription);
CurvedAnimation curvedAnimation = new CurvedAnimation(
parent: kAlwaysDismissedAnimation,
curve: Curves.ease
);
expect(curvedAnimation, hasOneLineDescription);
curvedAnimation.reverseCurve = Curves.elasticOut;
expect(curvedAnimation, hasOneLineDescription);
final AnimationController controller = new AnimationController(
duration: const Duration(milliseconds: 500),
vsync: const TestVSync(),
);
controller
..value = 0.5
..reverse();
curvedAnimation = new CurvedAnimation(
parent: controller,
curve: Curves.ease,
reverseCurve: Curves.elasticOut
);
expect(curvedAnimation, hasOneLineDescription);
controller.stop();
});
test('ProxyAnimation.toString control test', () {
final ProxyAnimation animation = new ProxyAnimation();
expect(animation.value, 0.0);
expect(animation.status, AnimationStatus.dismissed);
expect(animation, hasOneLineDescription);
animation.parent = kAlwaysDismissedAnimation;
expect(animation, hasOneLineDescription);
});
test('ProxyAnimation set parent generates value changed', () {
final AnimationController controller = new AnimationController(
vsync: const TestVSync(),
);
controller.value = 0.5;
bool didReceiveCallback = false;
final ProxyAnimation animation = new ProxyAnimation()
..addListener(() {
didReceiveCallback = true;
});
expect(didReceiveCallback, isFalse);
animation.parent = controller;
expect(didReceiveCallback, isTrue);
didReceiveCallback = false;
expect(didReceiveCallback, isFalse);
controller.value = 0.6;
expect(didReceiveCallback, isTrue);
});
test('ReverseAnimation calls listeners', () {
final AnimationController controller = new AnimationController(
vsync: const TestVSync(),
);
controller.value = 0.5;
bool didReceiveCallback = false;
void listener() {
didReceiveCallback = true;
}
final ReverseAnimation animation = new ReverseAnimation(controller)
..addListener(listener);
expect(didReceiveCallback, isFalse);
controller.value = 0.6;
expect(didReceiveCallback, isTrue);
didReceiveCallback = false;
animation.removeListener(listener);
expect(didReceiveCallback, isFalse);
controller.value = 0.7;
expect(didReceiveCallback, isFalse);
expect(animation, hasOneLineDescription);
});
test('TrainHoppingAnimation', () {
final AnimationController currentTrain = new AnimationController(
vsync: const TestVSync(),
);
final AnimationController nextTrain = new AnimationController(
vsync: const TestVSync(),
);
currentTrain.value = 0.5;
nextTrain.value = 0.75;
bool didSwitchTrains = false;
final TrainHoppingAnimation animation = new TrainHoppingAnimation(
currentTrain, nextTrain, onSwitchedTrain: () {
didSwitchTrains = true;
});
expect(didSwitchTrains, isFalse);
expect(animation.value, 0.5);
expect(animation, hasOneLineDescription);
nextTrain.value = 0.25;
expect(didSwitchTrains, isTrue);
expect(animation.value, 0.25);
expect(animation, hasOneLineDescription);
expect(animation.toString(), contains('no next'));
});
test('AnimationMean control test', () {
final AnimationController left = new AnimationController(
value: 0.5,
vsync: const TestVSync(),
);
final AnimationController right = new AnimationController(
vsync: const TestVSync(),
);
final AnimationMean mean = new AnimationMean(left: left, right: right);
expect(mean, hasOneLineDescription);
expect(mean.value, equals(0.25));
final List<double> log = <double>[];
void logValue() {
log.add(mean.value);
}
mean.addListener(logValue);
right.value = 1.0;
expect(mean.value, equals(0.75));
expect(log, equals(<double>[0.75]));
log.clear();
mean.removeListener(logValue);
left.value = 0.0;
expect(mean.value, equals(0.50));
expect(log, isEmpty);
});
test('CurvedAnimation with bogus curve', () {
final AnimationController controller = new AnimationController(
vsync: const TestVSync(),
);
final CurvedAnimation curved = new CurvedAnimation(parent: controller, curve: new BogusCurve());
expect(() { curved.value; }, throwsFlutterError);
});
}