Luthermilla Ecole
Luthermilla Ecole

Reputation: 786

Progress bar while logging in with firebase Flutter

I am building an application, and I would like to show a progress bar while the user is waiting to be logged-in in the platform.

How can I add a circle progress bar while I am awaiting?

 Future<void> validateAndSubmit() async {
  if (validateAndSave()) {
   try {
    final Auth auth = await AuthFactory.getAuth();
    final String userId = await auth
        .signInWithEmailAndPassword(_email, _password)
        .whenComplete(() =>
            Navigator.of(context).popAndPushNamed(RootPage.routeName));
       print('Signed In:$userId');
     } catch (e) {
     print('Error:$e');
     print(e.toString());
    }
  }
 } 

Upvotes: 2

Views: 825

Answers (1)

krumpli
krumpli

Reputation: 742

Since you use future, the best way would be to control a CircularProgressIndicator() with a boolean inside your method like this:

Future<void> validateAndSubmit() async {
  setState(( {
      _isLoading = true;
    });

  if (validateAndSave()) {
   try {
    final Auth auth = await AuthFactory.getAuth();
    final String userId = await auth
        .signInWithEmailAndPassword(_email, _password)
        .whenComplete(() =>
            {
              setState(() {
               _isLoading = false;
            });
           Navigator.of(context).popAndPushNamed(RootPage.routeName));
         }
       print('Signed In:$userId');
     } catch (e) {
     print('Error:$e');
     print(e.toString());
    }
  }
 } 

and then somewhere in your widget tree:

_isLoading ? CircularProgressIndicator() : Other widget...

Upvotes: 1

Related Questions