-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Allow Passing an AnimationController to CircularProgressIndicator (Fix #165741) #170380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8a1b072
825efbc
bd6f142
e70097a
8480570
4efde13
e8e58c1
4e8686e
18349ab
07ed6df
8a7091f
0391df9
633bba3
ed0fe82
4e59d1a
b54ab30
24847c1
73ed374
ff46c0b
24d9add
c173a39
cd37464
7d1660c
e153e71
81722ae
e6b6346
688e2e0
7b9c42b
a229099
33c9903
df0dd2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -567,6 +567,80 @@ void main() { | |
expect(tester.binding.transientCallbackCount, 0); | ||
}); | ||
|
||
testWidgets('LinearProgressIndicator reflects controller value', (WidgetTester tester) async { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the point of both tests. The controller's value is passed into the progress indicator directly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR is adding a new property that increases the API surface. Tests should check that that property is respected (for both progress indicators and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In what way should I check that its respected ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Any idea's on how you would tackle this, differently ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dkwingsmt What do you think about this ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One example I can think of is passing the same animation controller into multiple progress indicators on the same page and verifying at certain points they all have the same value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can't be done because everything is private in the class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Testing in the framework focuses on observable behavior, not implementation details. In There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @Sten435, did you run into problems adding a test that fit the description in https://github.com/flutter/flutter/pull/170380/files#r2214098382? |
||
final AnimationController controller = AnimationController( | ||
Sten435 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
vsync: tester, | ||
duration: const Duration(seconds: 2), | ||
); | ||
|
||
Widget buildWidget(AnimationController? controller) { | ||
return MaterialApp( | ||
home: Material( | ||
child: Center( | ||
child: AnimatedBuilder( | ||
animation: controller!, | ||
builder: (BuildContext context, Widget? child) { | ||
return LinearProgressIndicator(value: controller.value); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
await tester.pumpWidget(buildWidget(controller)); | ||
await tester.pump(const Duration(milliseconds: 100)); // build | ||
|
||
expect(find.byType(LinearProgressIndicator), paints..rect()); | ||
|
||
controller.value = 0.5; | ||
await tester.pump(); // triggers rebuild via AnimatedBuilder | ||
|
||
expect(find.byType(LinearProgressIndicator), paints..rect()); | ||
controller.dispose(); | ||
}); | ||
|
||
testWidgets('LinearProgressIndicator paints at 50% when controller value is 0.5', ( | ||
WidgetTester tester, | ||
) async { | ||
final AnimationController controller = AnimationController( | ||
Sten435 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
vsync: tester, | ||
duration: const Duration(seconds: 2), | ||
); | ||
|
||
Widget buildWidget(AnimationController? controller) { | ||
return MaterialApp( | ||
home: Material( | ||
child: Center( | ||
child: SizedBox( | ||
width: 200, | ||
child: AnimatedBuilder( | ||
animation: controller!, | ||
builder: (BuildContext context, Widget? child) { | ||
return LinearProgressIndicator(value: controller.value); | ||
}, | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
await tester.pumpWidget(buildWidget(controller)); | ||
await tester.pump(); | ||
|
||
controller.value = 0.5; | ||
await tester.pump(); | ||
|
||
expect( | ||
find.byType(LinearProgressIndicator), | ||
paints | ||
..rect(rect: const Rect.fromLTWH(0.0, 0.0, 200.0, 4.0)) // background | ||
..rect(rect: const Rect.fromLTWH(0.0, 0.0, 100.0, 4.0)), // progress at 50% | ||
); | ||
controller.dispose(); | ||
}); | ||
|
||
testWidgets('CircularProgressIndicator paint colors', (WidgetTester tester) async { | ||
const Color green = Color(0xFF00FF00); | ||
const Color blue = Color(0xFF0000FF); | ||
|
Uh oh!
There was an error while loading. Please reload this page.