Home > Back-end >  type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Future
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Future

Time:07-21

I am trying to get JSON response but I am getting this error:

type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'FutureOr<List<dynamic>>

here is my code:

Future<List> loadFriendParties (String id) async {
    //TODO change userId
    var request = await EndPoints.getUserInterest(id);
    print(request.body);
    print(request.statusCode);
    if (request.statusCode == 200) {
      return jsonDecode(request.body)['data'] ?? [];
    }
    return [];
  }

and

FutureBuilder(
    future: myFriendPartiesLoader = loadFriendParties(element['id']),
    builder: (context, snapshot) {
         print('snapshot: ${snapshot.data}');
         print('snapshot2: ${snapshot}');

above prints are giving me this:

snapshot: null
snapshot2: AsyncSnapshot<List<dynamic>>(ConnectionState.done, null, type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'FutureOr<List<dynamic>>'

and this is my JSON:

{
    "data": {
        "intrested": [
            {
                "event_name": "Karaoke",
                "city": "Warszawa
                "description": "text",
            },
            {
                "event_name": "PAPUGOWE",
                "city": "Toruń",
                "description": "text",
            }
        ],
        "participate": [],
        "be_today": [
            {
                "name": "Ryba Piła",
                "city": "Gdańsk",
                "description": "text",
            },
            {
                "name": "Moon Club",
                "city": "Toruń",
                "description": "text.",
            }
        ]
    }
}

How to handle response from JSON in this case properly?

CodePudding user response:

Future<List> loadFriendParties (String id) async {
    //TODO change userId
    var request = await EndPoints.getUserInterest(id);
    print(request.body);
    print(request.statusCode);
    if (request.statusCode == 200) {
    
     Map<String, dynamic> json = jsonDecode(request.body)['data'];
     //then return what you want here
     
    }
    return [];
  }
  • Related