Home > Enterprise >  "A nullable expression can't be used as a condition.\nTry checking that the value isn
"A nullable expression can't be used as a condition.\nTry checking that the value isn

Time:12-07

 handleSignUp() async {
      if (await authProvider.register(
        name: nameController.text,
        username: usernameController.text,
        email: emailController.text,
        password: passwordController.text,
      )){

please help me for this to solve thanktyouuu

CodePudding user response:

It is possible your register will return null, you can directly use

if(await method()==true){...}

I will prefer to create a separate variable for this.

final bool isRegistered  = await authProvider.register(
        name: nameController.text,
        username: usernameController.text,
        email: emailController.text,
        password: passwordController.text,
      ) ?? false; // providing false on null case

 if(isRegistered) { ....}

CodePudding user response:

if (await authProvider.register(
      name: nameController.text,
      username: usernameController.text,
      email: emailController.text,
      password: passwordController.text,
    ) !=
    null) {
  print('Registered');
}else{
  print('Something went wrong');
}
  • Related