【问题标题】:"A nullable expression can't be used as a condition.\nTry checking that the value isn't 'null' before using it as a condition\"可空表达式不能用作条件。\\n在将其用作条件之前,请尝试检查该值是否为\'null\'
【发布时间】:2022-12-18 23:28:08
【问题描述】:
 handleSignUp() async {
      if (await authProvider.register(
        name: nameController.text,
        username: usernameController.text,
        email: emailController.text,
        password: passwordController.text,
      )){

请帮我解决这个问题 thanktyouuu

【问题讨论】:

    标签: android flutter dart async-await dart-null-safety


    【解决方案1】:

    有可能你的register会返回null,你可以直接使用

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

    我宁愿为此创建一个单独的变量。

    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) { ....}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-16
      • 1970-01-01
      • 2011-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多