简体   繁体   中英

Not able to display firebase auth exception error as toast message in flutter

I am making an app in flutter using firebase for login and signup functionaity. I want to display the exception caused while this firebase auth as flutter toast so that the user can understand what's going wrong.

But the error.message provided by firebase is nullable string and flutter toast message needs a string as parameter so it' showing this error

The argument type 'String?' can't be assigned to the parameter type 'String'.dart(argument_type_not_assignable)

Code and error:

代码和错误

Can anyone help me out to display this?

 try{
   // code here
 }
 on FirebaseAuthException catch (error) {
        Fluttertoast.showToast(msg: error.message, gravity: ToastGravity.TOP);
      }

You can use the ! (bang) operator:

Fluttertoast.showToast(msg: error!.message!, gravity: ToastGravity.TOP);

You can read more about argument_type_not_assignable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM