Allow Duration.Zero for animateTo (#11515)
This commit is contained in:
parent
802d5d2028
commit
ec9df2f269
@ -341,7 +341,10 @@ class AnimationController extends Animation<double>
|
||||
}
|
||||
stop();
|
||||
if (simulationDuration == Duration.ZERO) {
|
||||
assert(value == target);
|
||||
if (value != target) {
|
||||
_value = target.clamp(lowerBound, upperBound);
|
||||
notifyListeners();
|
||||
}
|
||||
_status = (_direction == _AnimationDirection.forward) ?
|
||||
AnimationStatus.completed :
|
||||
AnimationStatus.dismissed;
|
||||
|
@ -6,6 +6,7 @@ import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/animation.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../scheduler/scheduler_tester.dart';
|
||||
@ -381,4 +382,17 @@ void main() {
|
||||
expect(statusLog, equals(<AnimationStatus>[ AnimationStatus.reverse, AnimationStatus.dismissed ]));
|
||||
expect(controller.value, currentValue);
|
||||
});
|
||||
|
||||
test('animateTo can deal with duration == Duration.ZERO', () {
|
||||
final AnimationController controller = new AnimationController(
|
||||
duration: const Duration(milliseconds: 100),
|
||||
vsync: const TestVSync(),
|
||||
);
|
||||
|
||||
controller.forward(from: 0.2);
|
||||
expect(controller.value, 0.2);
|
||||
controller.animateTo(1.0, duration: Duration.ZERO);
|
||||
expect(SchedulerBinding.instance.transientCallbackCount, equals(0), reason: 'Expected no animation.');
|
||||
expect(controller.value, 1.0);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user