OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 import 'curves.dart'; | |
6 import 'dart:async'; | |
7 import 'generators.dart'; | |
8 | |
9 class Animation { | |
10 Stream<double> get onValueChanged => _controller.stream; | |
11 | |
12 double get value => _value; | |
13 | |
14 void set value(double value) { | |
15 stop(); | |
16 _setValue(value); | |
17 } | |
18 | |
19 bool get isAnimating => _animation != null; | |
20 | |
21 StreamController _controller = new StreamController(sync: true); | |
22 | |
23 AnimationGenerator _animation; | |
24 | |
25 double _value; | |
26 | |
27 void _setValue(double value) { | |
28 _value = value; | |
29 _controller.add(_value); | |
30 } | |
31 | |
32 void stop() { | |
33 if (_animation != null) { | |
34 _animation.cancel(); | |
35 _animation = null; | |
36 } | |
37 } | |
38 | |
39 void animateTo(double newValue, double duration, | |
40 { Curve curve: linear, double initialDelay: 0.0 }) { | |
41 stop(); | |
42 | |
43 _animation = new AnimationGenerator( | |
44 duration: duration, | |
45 begin: _value, | |
46 end: newValue, | |
47 curve: curve, | |
48 initialDelay: initialDelay); | |
49 | |
50 _animation.onTick.listen(_setValue, onDone: () { | |
51 _animation = null; | |
52 }); | |
53 } | |
54 } | |
OLD | NEW |