| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'curves.dart'; | 5 import 'curves.dart'; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'generators.dart'; | 7 import 'generators.dart'; |
| 8 | 8 |
| 9 typedef void Callback (); |
| 10 |
| 9 class AnimatedValue { | 11 class AnimatedValue { |
| 10 StreamController _controller = new StreamController(sync: true); | 12 StreamController _controller = new StreamController.broadcast(sync: true); |
| 11 AnimationGenerator _animation; | 13 AnimationGenerator _animation; |
| 12 Completer _completer; | 14 Completer _completer; |
| 13 double _value; | 15 double _value; |
| 14 | 16 |
| 15 AnimatedValue(double initial) { | 17 AnimatedValue(double initial, { Callback onChange }) { |
| 16 _value = initial; | 18 _value = initial; |
| 19 _onChange = onChange; |
| 17 } | 20 } |
| 21 Callback _onChange; |
| 18 | 22 |
| 19 // A stream of change in value from |initial|. The stream does not | 23 // A stream of change in value from |initial|. The stream does not |
| 20 // contain the initial value. Consumers should check the initial value via | 24 // contain the initial value. Consumers should check the initial value via |
| 21 // the |value| accessor. | 25 // the |value| accessor. |
| 22 Stream<double> get onValueChanged => _controller.stream; | 26 Stream<double> get onValueChanged => _controller.stream; |
| 23 | 27 |
| 24 double get value => _value; | 28 double get value => _value; |
| 25 | 29 |
| 26 void set value(double value) { | 30 void set value(double value) { |
| 27 stop(); | 31 stop(); |
| 28 _setValue(value); | 32 _setValue(value); |
| 29 } | 33 } |
| 30 | 34 |
| 31 bool get isAnimating => _animation != null; | 35 bool get isAnimating => _animation != null; |
| 32 | 36 |
| 33 void _setValue(double value) { | 37 void _setValue(double value) { |
| 34 _value = value; | 38 _value = value; |
| 35 _controller.add(_value); | 39 _controller.add(_value); |
| 40 if (_onChange != null) |
| 41 _onChange(); |
| 36 } | 42 } |
| 37 | 43 |
| 38 void _done() { | 44 void _done() { |
| 39 _animation = null; | 45 _animation = null; |
| 40 if (_completer == null) | 46 if (_completer == null) |
| 41 return; | 47 return; |
| 42 Completer completer = _completer; | 48 Completer completer = _completer; |
| 43 _completer = null; | 49 _completer = null; |
| 44 completer.complete(_value); | 50 completer.complete(_value); |
| 45 } | 51 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 67 return _completer.future; | 73 return _completer.future; |
| 68 } | 74 } |
| 69 | 75 |
| 70 double get remainingTime { | 76 double get remainingTime { |
| 71 if (_animation == null) | 77 if (_animation == null) |
| 72 return 0.0; | 78 return 0.0; |
| 73 return _animation.remainingTime; | 79 return _animation.remainingTime; |
| 74 } | 80 } |
| 75 | 81 |
| 76 } | 82 } |
| OLD | NEW |