'Unhandled Exception: type '_InternalLinkedHashMap<String, String>' is not a subtype of type 'String' in type cast

I am trying to create a sign up page for my app.

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

and using this here so that people can create an account:

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

When I try to run the app, it runs normally. But when I fill in the details and try to create an account it doesn't really give an error- it just doesn't go through. After reading the console following lines come up:

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type '_InternalLinkedHashMap' is not a subtype of type 'String' in type cast

I tried researching on stackoverflow and github, this error InternalLinkedHasMap pops up while networking with apis. But I couldn't find an instance that was solving my issue.



Solution 1:[1]

I think I'm a little late. Well, in case someone needs it.

 body: {
        "user" : "{
          "UserName":username,
          "password":password,
          "Name": name,
        }"
       }
    );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fahmida