Parsing JSON in flutter cast<RK, RV>() => Map<RK, RV>, No such method error Parsing JSON in flutter cast<RK, RV>() => Map<RK, RV>, No such method error json json

Parsing JSON in flutter cast<RK, RV>() => Map<RK, RV>, No such method error


the thing is that in your response you don't have a list of the users, you only have one user and you are trying to parse it to a list of the users. So, please replace

final parsed = jsonDecode(response.body).cast<Map<String, dynamic>>();return parsed      .map<CurrentUser>((json) => CurrentUser.fromJson(json))      .toList();

With parsing to single user:

final parsed = json.decode(resource);final user = CurrentUser.fromJson(parsed);