0

I have the following code which basically handles an error and then the goal is to show a snackbar. However, I am currently stuck at adding async to the builder function. How can I accomplish this?

   return StretchableButton(
     buttonColor: Color(0xFF1877F2),
     borderRadius: borderRadius,
     splashColor: splashColor,
         onPressed: () async {
           Builder(
       builder: (context) async =>  
       await Provider.of<Auth>(context, listen: false).signInFB(context).catchError((e) {
              print('Inside catch error fb'); 
     if(e.code == 'account-exists-with-different-credential')
       {
            return AlertDialog(
       title: Text('You have already used the same email to login'));
       }                          
   });
    );
            
       
      
        
mcfred
  • 1,183
  • 2
  • 29
  • 68

2 Answers2

0

the build() function can not be async.

you can use FutureBuilder where you return a placeholder (like a Container()) while the async result is not yet ready or move the async code to initState() and update the state using a setState when the value is ready to have the build executed again.

Benedikt J Schlegel
  • 1,707
  • 1
  • 10
  • 23
0

You can use FutureBuilder to achieve the expected result; Read more about FutureBuilder here https://prabhanu.medium.com/how-to-get-data-from-async-function-to-show-on-a-widget-32dfa2df725a

prahack
  • 1,267
  • 1
  • 15
  • 19