Commit 552f26d7 authored by Hixie's avatar Hixie

Stop AnimatedContainer from animating every build

It turns out that an AnimatedContainer with a BoxDecoration would
start animating every single time it was built, whether or not the
container's decoration had changed.
parent 6b2d121f
......@@ -30,6 +30,8 @@ class Scheduler {
Map<int, SchedulerCallback> _transientCallbacks = new LinkedHashMap<int, SchedulerCallback>();
final Set<int> _removedIds = new Set<int>();
int get transientCallbackCount => _transientCallbacks.length;
/// Called by the engine to produce a new frame.
///
/// This function first calls all the callbacks registered by
......
......@@ -66,6 +66,7 @@ class AnimatedContainer extends StatefulComponent {
}
final Widget child;
final BoxConstraints constraints;
final BoxDecoration decoration;
final BoxDecoration foregroundDecoration;
......@@ -95,7 +96,7 @@ class _AnimatedContainerState extends State<AnimatedContainer> {
void initState() {
super.initState();
_performance = new Performance(duration: config.duration)
_performance = new Performance(duration: config.duration, debugLabel: '${config.toStringShort()}')
..timing = new AnimationTiming(curve: config.curve)
..addListener(_updateAllVariables);
_configAllVariables();
......
......@@ -202,8 +202,12 @@ abstract class Widget {
/// Inflates this configuration to a concrete instance.
Element createElement();
String toStringShort() {
return key == null ? '$runtimeType' : '$runtimeType-$key';
}
String toString() {
final String name = key == null ? '$runtimeType' : '$runtimeType-$key';
final String name = toStringShort();
final List<String> data = <String>[];
debugFillDescription(data);
if (data.isEmpty)
......
import 'package:flutter/animation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:test/test.dart';
......@@ -45,4 +46,51 @@ void main() {
});
});
test('AnimatedContainer overanimate test', () {
testWidgets((WidgetTester tester) {
tester.pumpWidget(
new AnimatedContainer(
duration: const Duration(milliseconds: 200),
decoration: new BoxDecoration(
backgroundColor: new Color(0xFF00FF00)
)
)
);
expect(scheduler.transientCallbackCount, 0);
tester.pump(new Duration(seconds: 1));
expect(scheduler.transientCallbackCount, 0);
tester.pumpWidget(
new AnimatedContainer(
duration: const Duration(milliseconds: 200),
decoration: new BoxDecoration(
backgroundColor: new Color(0xFF00FF00)
)
)
);
expect(scheduler.transientCallbackCount, 0);
tester.pump(new Duration(seconds: 1));
expect(scheduler.transientCallbackCount, 0);
tester.pumpWidget(
new AnimatedContainer(
duration: const Duration(milliseconds: 200),
decoration: new BoxDecoration(
backgroundColor: new Color(0xFF0000FF)
)
)
);
expect(scheduler.transientCallbackCount, 1); // this is the only time an animation should have started!
tester.pump(new Duration(seconds: 1));
expect(scheduler.transientCallbackCount, 0);
tester.pumpWidget(
new AnimatedContainer(
duration: const Duration(milliseconds: 200),
decoration: new BoxDecoration(
backgroundColor: new Color(0xFF0000FF)
)
)
);
expect(scheduler.transientCallbackCount, 0);
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment