I'm using the ModalProgressHud
to display a spinner while it's waiting for an answer from the server. I want to test that when the user taps the button, the CircularProgressIndicator
is shown. My problem is that the pumpAndSettle()
will timeout because of this CircularProgressIndicator
that, I think, it's constantly rebuilding itself. Any suggestion on how to test the presence of a CircularProgressIndicator
?
This is my test:
testWidgets(
'Should show a CircularProgressIndicator while it tries to login', (WidgetTester tester) async {
await (tester.pumpWidget(
generateApp(LoginView())
));
await tester.pumpAndSettle();
await tester.tap(find.byType(FlatButton));
await tester.pumpAndSettle();
expect(find.byType(CircularProgressIndicator), findsOneWidget);
});
Creating Circular Progress Indicator Flutter provides a class called CircularProgressIndicator. To create a circular progress indicator we have to call its constructor. There are no required properties for this widget so we can directly call the constructor.
Get Started. Create a variable name _state in _MyHomePageState class and initialize it with the value 0 . Now in the MatrialButton Widget in OnPressed , we will change the state to show progress. Now, change the state of button with animateButton() method.
Step 1: Locate the CircularProgressIndicator of which you would like to change the color. Step 2: Add the valueColor property. Step 3: Assign the AlwaysStoppedAnimation() . Step 4: Inside the AlwaysStoppedAnimation(), add the color of your choice.
Your thinking is correct - you cannot pumpAndSettle
because CircularProgressIndicator animates indefinitely. You could try using tester.pump()
with a timeout instead of pumpAndSettle
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With