'How can I add whole object as parameter in flutter post request?

"UserDtls":{
    "DisplayName": "Picker",
        "UserName": "Picker",
        "Password": "",
        "EncryptPassword": "",
        "UserId": 5,
        "RoleId": 5,
        "RoleName": "Picker",
        "EmpId": 5,
        "IsActive": "Y",
        "BranchId": 1,
        "BranchCode": "BR01",
        "BranchName": "",
        "City": "1",
        "EmpNo": "E00005",
        "EmpName": "Picker",
        "EmpMobNo": "",
        "CompanyId": 1,
        "CompanyCode": "01",
        "CompanyName": "",
        "CompCityName": ""
},
"UserName":"Picker",
"UserId":5,
"RefreshToken":"refresh token",
"GrantType":"refresh_token"

On the code above, I am not able to pass "UserDtls". Giving me error as NoSuchMethodError: Class 'JsonCodec' has no instance method '[]'. Flutter post method

The following is my post request:

 Map<String, dynamic> refreshTokenData = {
      "GrantType": Constants.grantTypeRefreshToken,
      'RefreshToken': refreshToken,
      'Username': userName,
      "UserId": userId,
      "UserDtls": //...
}


Response response = await post(
        Uri.parse(AppUrl.login),
        body: jsonEncode(refreshTokenData),
        headers: {'Content-Type': 'application/json; charset=UTF-8'},
      );

Can someone please help me out with this?



Sources

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

Source: Stack Overflow

Solution Source