Home > Back-end >  Null check operator used on a null value on Flutter
Null check operator used on a null value on Flutter

Time:01-04

I have two lines of codes that are giving me an error of "Null check operator used on a null value". I tried various methods but couldn't figure out a valid one. Can anyone help me fix?

var chatRoomId = getChatRoomIdByUsernames(myUserName!, username);

and

        SharedPreferenceHelper().saveUserName(userDetails.email!.replaceAll("@gmail.com", ""));

CodePudding user response:

try this:

myUserName ?? '';

and as soon as possible search about "dart null safety".

CodePudding user response:

You can't use ! (null check operator) on null value

You have to use it like this

var chatRoomId = getChatRoomIdByUsernames(myUserName ?? '', username);
  •  Tags:  
  • Related