Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

showing CircularProgressIndicator until the function end | flutter

I want to show CircularProgressIndicator until the function end, So I use this method,

  • set bool isLoading = false;

  • and this is the function,

    MEDevel.com: Open-source for Healthcare and Education

    Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

    Visit Medevel

    verifyPhoneNumber(String input) async {
      setState(() {
        isLoading = true;
      });
      await AuthMethods().phoneSign(context, input);
      setState(() {
        isLoading = false;
      });}
    
  • For this screen

                  Scaffold(
                          body:  
                          isLoading
                              ? Center(
                                  child: CircularProgressIndicator(color: darkblueColor),
                                )
                              : Column(
                                  children: [ 
                                   IntlPhoneField(
                                        onChanged: (phone) {
                                          setState(() {
                                            fullNumber = phone.completeNumber;
                                          });
                                        },
                                      ),
                                   CustomButton(
                                        onTap: () {
                                              verifyPhoneNumber(fullNumber);
                                        },
                                        text: "Next",
                                        height: 50,
                                      ),],),)
    

This is not working!. Can futureBuilderapply for this & If it’s yes, How?

this function work for firebase phoneAuth, There is phoneSign inside AuthMethods class.

>Solution :

For question snippet , you need to await for verifyPhoneNumber

Future<void> verifyPhoneNumber(String input) async {
  setState(() {
    isLoading = true;
  });
  await AuthMethods().phoneSign(context, input);
  setState(() {
    isLoading = false;
  });}

Make the async method

CustomButton(
   onTap: ()async {
         await verifyPhoneNumber(fullNumber); // you need to await for future
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading