mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Merge pull request #850 from HansMuller/progress-bar-animation
Fix ProgressIndicators and add a regression test Added some unit test infrastucture for checking layers.
This commit is contained in:
commit
28e432afa6
@ -31,6 +31,7 @@ abstract class ProgressIndicator extends StatefulComponent {
|
||||
double get _animationValue => (_animation.variable as AnimatedValue<double>).value;
|
||||
Color get _backgroundColor => Theme.of(this).primarySwatch[200];
|
||||
Color get _valueColor => Theme.of(this).primaryColor;
|
||||
Object get _customPaintToken => value != null ? value : _animationValue;
|
||||
|
||||
void initState() {
|
||||
_animation = new AnimationPerformance()
|
||||
@ -92,7 +93,7 @@ class LinearProgressIndicator extends ProgressIndicator {
|
||||
|
||||
Widget _buildIndicator() {
|
||||
return new Container(
|
||||
child: new CustomPaint(callback: _paint),
|
||||
child: new CustomPaint(callback: _paint, token: _customPaintToken),
|
||||
constraints: new BoxConstraints.tightFor(
|
||||
width: double.INFINITY,
|
||||
height: _kLinearProgressIndicatorHeight
|
||||
@ -138,7 +139,7 @@ class CircularProgressIndicator extends ProgressIndicator {
|
||||
|
||||
Widget _buildIndicator() {
|
||||
return new Container(
|
||||
child: new CustomPaint(callback: _paint),
|
||||
child: new CustomPaint(callback: _paint, token: _customPaintToken),
|
||||
constraints: new BoxConstraints(
|
||||
minWidth: _kMinCircularProgressIndicatorSize,
|
||||
minHeight: _kMinCircularProgressIndicatorSize
|
||||
|
||||
@ -9,6 +9,7 @@ class TestRenderView extends RenderView {
|
||||
attach();
|
||||
rootConstraints = new ViewConstraints(size: _kTestViewSize);
|
||||
scheduleInitialLayout();
|
||||
scheduleInitialPaint(new TransformLayer(transform: new Matrix4.identity()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,6 +64,20 @@ class WidgetTester {
|
||||
TestApp _app;
|
||||
RenderView _renderView;
|
||||
|
||||
List<Layer> _layers(Layer layer) {
|
||||
List<Layer> result = [layer];
|
||||
if (layer is ContainerLayer) {
|
||||
ContainerLayer root = layer;
|
||||
Layer child = root.firstChild;
|
||||
while(child != null) {
|
||||
result.addAll(_layers(child));
|
||||
child = child.nextSibling;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
List<Layer> get layers => _layers(_renderView.layer);
|
||||
|
||||
void walkWidgets(WidgetTreeWalker walker) {
|
||||
void walk(Widget widget) {
|
||||
walker(widget);
|
||||
@ -113,4 +128,14 @@ class WidgetTester {
|
||||
Component.flushBuild();
|
||||
RenderObject.flushLayout();
|
||||
}
|
||||
|
||||
// TODO(hansmuller): just having one pumpFrame() fn would be preferable.
|
||||
void pumpPaintFrame(WidgetBuilder builder) {
|
||||
_app.builder = builder;
|
||||
Component.flushBuild();
|
||||
RenderObject.flushLayout();
|
||||
_renderView.updateCompositingBits();
|
||||
RenderObject.flushPaint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
24
sky/unit/test/widget/progress_indicator_test.dart
Normal file
24
sky/unit/test/widget/progress_indicator_test.dart
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
import 'package:sky/rendering.dart';
|
||||
import 'package:sky/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'build_utils.dart';
|
||||
|
||||
void main() {
|
||||
test('LinearProgressIndicator changes when its value changes', () {
|
||||
WidgetTester tester = new WidgetTester();
|
||||
|
||||
tester.pumpPaintFrame(() {
|
||||
return new Block([new LinearProgressIndicator(value: 0.0)]);
|
||||
});
|
||||
List<Layer> layers1 = tester.layers;
|
||||
|
||||
tester.pumpPaintFrame(() {
|
||||
return new Block([new LinearProgressIndicator(value: 0.5)]);
|
||||
});
|
||||
List<Layer> layers2 = tester.layers;
|
||||
|
||||
expect(layers1, isNot(equals(layers2)));
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user