Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test CircularProgressIndicator

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);
  });
like image 876
Little Monkey Avatar asked Jul 16 '19 14:07

Little Monkey


People also ask

How do you use CircularProgressIndicator in flutter?

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.

How do I show the progress bar on button click in flutter?

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.

How do you change the color of a CircularProgressIndicator in flutter?

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.


1 Answers

Your thinking is correct - you cannot pumpAndSettle because CircularProgressIndicator animates indefinitely. You could try using tester.pump() with a timeout instead of pumpAndSettle.

like image 107
MichaelM Avatar answered Nov 20 '22 00:11

MichaelM