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);