Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

flutter : Map method return dynamic not specific object

I get JSON data from Api and with map method I changed map to my specific class :

  final result = await supaService.supabase.client
      .from('user_able')
      .select()
      .eq('user_id', uuid)
      .execute();

  final response = result.data[0]['user'];
  final databaseusers =
      response.map((e) => DataBaseModel.fromJson(e)).toList();

Now I want to return List but I got :

Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<DataBaseModel>'

Why? Map method should return list of my object but it returns dynamic?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try to cast your list:

final databaseusers = response.map((e) => DataBaseModel.fromJson(e)).toList() as List<DataBaseModel>;

Also you can give a type when use the map

final databaseusers = response.map<DataBaseModel>((e) => DataBaseModel.fromJson(e)).toList();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading