未处理的异常:类型'_InternalLinkedHashMap <String,String>'不是强制类型转换

时间:2020-04-14 16:22:29

标签: flutter dart

我正在尝试为我的应用创建一个注册页面。

Future<int> attemptSignup (String name, String username, String password) async {
    var res = await http.post(
      'http://ec2-13-233-140-222.ap-south-1.compute.amazonaws.com:8000/Users',
       body: {
        "user" : {
          "UserName":username,
          "password":password,
          "Name": name,
        }
       }
    );
    return res.statusCode;
  }

并在这里使用它,以便人们可以创建一个帐户:

onTap: () async {

      var username = _usernameController.text;
      var password = _passwordController.text;
      var name = _nameController.text;

      if( username.length < 4)
        displayDialog(context, "Invalid Username", "Username should be atleast 4 characters long");
      else if (password.length < 4)
        displayDialog(context, "Invalid password", "The password should be atleast 4 characters long");
      else {
        var res = await attemptSignup(name, username, password);
        if (res ==200)
          displayDialog(context, "Success", "The user was created. Go back and Log in now");
        else if (res ==409)
          displayDialog(context, "This Email is already registered", "Please login, or create an account with different Email");
        else{
          displayDialog(context, "Error", "An unknown error occurred");
          print(res);
        }
      }
    },

当我尝试运行该应用程序时,它会正常运行。但是,当我填写详细信息并尝试创建一个帐户时,它实际上并没有给出错误-只是没有通过。阅读控制台后,出现以下几行:

[ERROR:flutter / lib / ui / ui_dart_state.cc(157)]未处理的异常:类型'_InternalLinkedHashMap'在强制类型转换中不是'String'类型的子类型

我尝试研究stackoverflow和github,在使用api联网时会弹出此错误InternalLinkedHasMap。但是我找不到解决我问题的实例。

0 个答案:

没有答案