繁体   English   中英

“Null”类型不是“String”类型的子类型

[英]type 'Null' is not a subtype of type 'String'

我在登录功能中收到此错误

void _login() async {
  var user = LoginUser(
    emailId: _emailController.text,
    password: _passwordController.text,
  );

  try {
    CustomerLoginResponse response =
        await ApiManager().loginUser(user).catchError((err) {
      return Future<CustomerLoginResponse>.error(err);
    });

    if (response.successful) {
      showDataAlert();
      print(response.message);
    } else {
      print(response.message);
    }
  } catch (e) {
    print(e);
  }
}

我得到的错误:I/flutter ( 5362): type 'Null' is not a subtype of type 'String'

此错误消息通常表示您正在尝试将 Null 类型的值分配给需要 String 类型值的变量或字段。

要修复此错误,您需要确保您尝试分配给变量或字段的值是正确的类型。 如果您想允许交易为空的可能性,您可以使用“?” 运算符指定变量或字段可为空,

我敢打赌您的 emailController 或 passwordController 为空。 它不会将您的 TextField 条目中的文本传递给 _login。 您必须为每个分配控制器值。 不能肯定地说,但我会从那里开始。 让我们知道给您错误的确切行总是有帮助的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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