Fix the progress indicator demo (#3367)
This commit is contained in:
parent
efbcb0aa0c
commit
f7cf0d97ca
@ -10,43 +10,48 @@ class ProgressIndicatorDemo extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> {
|
class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> {
|
||||||
|
AnimationController _controller;
|
||||||
|
Animation<double> _animation;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
controller = new AnimationController(
|
_controller = new AnimationController(
|
||||||
duration: const Duration(milliseconds: 1500)
|
duration: const Duration(milliseconds: 1500)
|
||||||
)..forward();
|
)..forward();
|
||||||
|
|
||||||
animation = new CurvedAnimation(
|
_animation = new CurvedAnimation(
|
||||||
parent: controller,
|
parent: _controller,
|
||||||
curve: new Interval(0.0, 0.9, curve: Curves.ease),
|
curve: new Interval(0.0, 0.9, curve: Curves.ease),
|
||||||
reverseCurve: Curves.ease
|
reverseCurve: Curves.ease
|
||||||
)..addStatusListener((AnimationStatus status) {
|
)..addStatusListener((AnimationStatus status) {
|
||||||
if (status == AnimationStatus.dismissed)
|
if (status == AnimationStatus.dismissed)
|
||||||
controller.forward();
|
_controller.forward();
|
||||||
else if (status == AnimationStatus.completed)
|
else if (status == AnimationStatus.completed)
|
||||||
controller.reverse();
|
_controller.reverse();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation<double> animation;
|
@override
|
||||||
AnimationController controller;
|
void dispose() {
|
||||||
|
_controller.stop();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
void _handleTap() {
|
void _handleTap() {
|
||||||
setState(() {
|
setState(() {
|
||||||
// valueAnimation.isAnimating is part of our build state
|
// valueAnimation.isAnimating is part of our build state
|
||||||
if (controller.isAnimating) {
|
if (_controller.isAnimating) {
|
||||||
controller.stop();
|
_controller.stop();
|
||||||
} else {
|
} else {
|
||||||
switch (controller.status) {
|
switch (_controller.status) {
|
||||||
case AnimationStatus.dismissed:
|
case AnimationStatus.dismissed:
|
||||||
case AnimationStatus.forward:
|
case AnimationStatus.forward:
|
||||||
controller.forward();
|
_controller.forward();
|
||||||
break;
|
break;
|
||||||
case AnimationStatus.reverse:
|
case AnimationStatus.reverse:
|
||||||
case AnimationStatus.completed:
|
case AnimationStatus.completed:
|
||||||
controller.reverse();
|
_controller.reverse();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,19 +66,19 @@ class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> {
|
|||||||
),
|
),
|
||||||
new LinearProgressIndicator(),
|
new LinearProgressIndicator(),
|
||||||
new LinearProgressIndicator(),
|
new LinearProgressIndicator(),
|
||||||
new LinearProgressIndicator(value: animation.value),
|
new LinearProgressIndicator(value: _animation.value),
|
||||||
new CircularProgressIndicator(),
|
new CircularProgressIndicator(),
|
||||||
new SizedBox(
|
new SizedBox(
|
||||||
width: 20.0,
|
width: 20.0,
|
||||||
height: 20.0,
|
height: 20.0,
|
||||||
child: new CircularProgressIndicator(value: animation.value)
|
child: new CircularProgressIndicator(value: _animation.value)
|
||||||
),
|
),
|
||||||
new SizedBox(
|
new SizedBox(
|
||||||
width: 50.0,
|
width: 50.0,
|
||||||
height: 30.0,
|
height: 30.0,
|
||||||
child: new CircularProgressIndicator(value: animation.value)
|
child: new CircularProgressIndicator(value: _animation.value)
|
||||||
),
|
),
|
||||||
new Text('${(animation.value * 100.0).toStringAsFixed(1)}%${ controller.isAnimating ? "" : " (paused)" }')
|
new Text('${(_animation.value * 100.0).toStringAsFixed(1)}%${ _controller.isAnimating ? "" : " (paused)" }')
|
||||||
];
|
];
|
||||||
return new Column(
|
return new Column(
|
||||||
children: indicators
|
children: indicators
|
||||||
@ -95,7 +100,7 @@ class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> {
|
|||||||
child: new Container(
|
child: new Container(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 8.0),
|
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 8.0),
|
||||||
child: new AnimatedBuilder(
|
child: new AnimatedBuilder(
|
||||||
animation: animation,
|
animation: _animation,
|
||||||
builder: _buildIndicators
|
builder: _buildIndicators
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
70
packages/flutter/test/material/progress_indicator_test.dart
Normal file
70
packages/flutter/test/material/progress_indicator_test.dart
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
// The "can be constructed" tests that follow are primarily to ensure that any
|
||||||
|
// animations started by the progress indicators are stopped at dispose() time.
|
||||||
|
|
||||||
|
test('LinearProgressIndicator(value: 0.0) can be constructed', () {
|
||||||
|
testWidgets((WidgetTester tester) {
|
||||||
|
tester.pumpWidget(
|
||||||
|
new Center(
|
||||||
|
child: new SizedBox(
|
||||||
|
width: 200.0,
|
||||||
|
child: new LinearProgressIndicator(value: 0.0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('LinearProgressIndicator(value: null) can be constructed', () {
|
||||||
|
testWidgets((WidgetTester tester) {
|
||||||
|
tester.pumpWidget(
|
||||||
|
new Center(
|
||||||
|
child: new SizedBox(
|
||||||
|
width: 200.0,
|
||||||
|
child: new LinearProgressIndicator(value: null)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('CircularProgressIndicator(value: 0.0) can be constructed', () {
|
||||||
|
testWidgets((WidgetTester tester) {
|
||||||
|
tester.pumpWidget(
|
||||||
|
new Center(
|
||||||
|
child: new CircularProgressIndicator(value: 0.0)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('CircularProgressIndicator(value: null) can be constructed', () {
|
||||||
|
testWidgets((WidgetTester tester) {
|
||||||
|
tester.pumpWidget(
|
||||||
|
new Center(
|
||||||
|
child: new CircularProgressIndicator(value: null)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('LinearProgressIndicator changes when its value changes', () {
|
||||||
|
testElementTree((ElementTreeTester tester) {
|
||||||
|
tester.pumpWidget(new Block(children: <Widget>[new LinearProgressIndicator(value: 0.0)]));
|
||||||
|
List<Layer> layers1 = tester.layers;
|
||||||
|
tester.pumpWidget(new Block(children: <Widget>[new LinearProgressIndicator(value: 0.5)]));
|
||||||
|
List<Layer> layers2 = tester.layers;
|
||||||
|
expect(layers1, isNot(equals(layers2)));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -1,23 +0,0 @@
|
|||||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
import 'package:flutter/rendering.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:test/test.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
test('LinearProgressIndicator changes when its value changes', () {
|
|
||||||
testElementTree((ElementTreeTester tester) {
|
|
||||||
tester.pumpWidget(new Block(children: <Widget>[new LinearProgressIndicator(value: 0.0)]));
|
|
||||||
|
|
||||||
List<Layer> layers1 = tester.layers;
|
|
||||||
|
|
||||||
tester.pumpWidget(new Block(children: <Widget>[new LinearProgressIndicator(value: 0.5)]));
|
|
||||||
|
|
||||||
List<Layer> layers2 = tester.layers;
|
|
||||||
expect(layers1, isNot(equals(layers2)));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user