How do I parse a complex JSON in flutter - json

I want to parse a complex JSON in flutter,I have tried many things but I am not clear about the way things are happening.Can anyone explain how do I go about the situation:
{
"message": {
"header": {
"status_code": 200,
"execute_time": 0.021989107131958
},
"body": {
"track_list": [
{
"track": {
"track_id": 200357565,
"track_name": "The Climb Back",
"track_name_translation_list": [],
"track_rating": 99,
"commontrack_id": 113835591,
"instrumental": 0,
"explicit": 1,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 20,
"album_id": 39278073,
"album_name": "Lewis Street",
"artist_id": 486280,
"artist_name": "J. Cole",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/J-Cole\/The-Climb-Back?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/J-Cole\/The-Climb-Back\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-07-23T14:02:17Z",
"primary_genres": {
"music_genre_list": []
}
}
},
{
"track": {
"track_id": 200187374,
"track_name": "POPSTAR (feat. Drake)",
"track_name_translation_list": [],
"track_rating": 99,
"commontrack_id": 113684105,
"instrumental": 0,
"explicit": 1,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 6,
"album_id": 39216808,
"album_name": "POPSTAR (feat. Drake) - Single",
"artist_id": 24704782,
"artist_name": "DJ Khaled feat. Drake, Lil Wayne & Rick Ross",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/DJ-Khaled-feat-Drake-Lil-Wayne-Rick-Ross\/POPSTAR-Drake?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/DJ-Khaled-feat-Drake-Lil-Wayne-Rick-Ross\/POPSTAR-Drake\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-07-17T13:38:30Z",
"primary_genres": {
"music_genre_list": []
}
}
},
{
"track": {
"track_id": 200102123,
"track_name": "What's Love Got to Do with It",
"track_name_translation_list": [],
"track_rating": 99,
"commontrack_id": 113606423,
"instrumental": 0,
"explicit": 0,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 18,
"album_id": 39186667,
"album_name": "What's Love Got to Do with It",
"artist_id": 45989671,
"artist_name": "Kygo feat. Tina Turner",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/Kygo-Tina-Turner\/What-s-Love-Got-to-Do-with-It?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/Kygo-Tina-Turner\/What-s-Love-Got-to-Do-with-It\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-07-23T06:28:49Z",
"primary_genres": {
"music_genre_list": []
}
}
},
{
"track": {
"track_id": 194169151,
"track_name": "Blinding Lights",
"track_name_translation_list": [],
"track_rating": 100,
"commontrack_id": 104185748,
"instrumental": 0,
"explicit": 0,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 5583,
"album_id": 37216011,
"album_name": "After Hours",
"artist_id": 13937035,
"artist_name": "The Weeknd",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/The-Weeknd-3\/Blinding-Lights?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/The-Weeknd-3\/Blinding-Lights\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-07-09T11:24:05Z",
"primary_genres": {
"music_genre_list": [
{
"music_genre": {
"music_genre_id": 7,
"music_genre_parent_id": 34,
"music_genre_name": "Electronic",
"music_genre_name_extended": "Electronic",
"music_genre_vanity": "Electronic"
}
}
]
}
}
},
{
"track": {
"track_id": 198421234,
"track_name": "Savage Love (Laxed - Siren Beat)",
"track_name_translation_list": [],
"track_rating": 100,
"commontrack_id": 112136372,
"instrumental": 0,
"explicit": 1,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 454,
"album_id": 38617941,
"album_name": "Savage Love (Laxed - Siren Beat) - Single",
"artist_id": 45643815,
"artist_name": "Jawsh 685 feat. Jason Derulo",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/Jawsh-685-Jason-Derulo\/Savage-Love-Laxed-Siren-Beat?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/Jawsh-685-Jason-Derulo\/Savage-Love-Laxed-Siren-Beat\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-07-09T13:06:43Z",
"primary_genres": {
"music_genre_list": []
}
}
},
{
"track": {
"track_id": 189626475,
"track_name": "Watermelon Sugar",
"track_name_translation_list": [],
"track_rating": 100,
"commontrack_id": 104939195,
"instrumental": 0,
"explicit": 0,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 567,
"album_id": 36101498,
"album_name": "Fine Line",
"artist_id": 24505463,
"artist_name": "Harry Styles",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/Harry-Styles\/Watermelon-Sugar-2?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/Harry-Styles\/Watermelon-Sugar-2\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2019-12-12T16:57:16Z",
"primary_genres": {
"music_genre_list": []
}
}
},
{
"track": {
"track_id": 192324206,
"track_name": "One Margarita",
"track_name_translation_list": [],
"track_rating": 99,
"commontrack_id": 107705631,
"instrumental": 0,
"explicit": 0,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 62,
"album_id": 36710192,
"album_name": "Born Here Live Here Die Here",
"artist_id": 360257,
"artist_name": "Luke Bryan",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/Luke-Bryan\/One-Margarita?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/Luke-Bryan\/One-Margarita\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-03-13T08:54:41Z",
"primary_genres": {
"music_genre_list": [
{
"music_genre": {
"music_genre_id": 34,
"music_genre_parent_id": 0,
"music_genre_name": "Music",
"music_genre_name_extended": "Music",
"music_genre_vanity": "Music"
}
}
]
}
}
},
{
"track": {
"track_id": 195445553,
"track_name": "ROCKSTAR (feat. Roddy Ricch)",
"track_name_translation_list": [],
"track_rating": 99,
"commontrack_id": 109586143,
"instrumental": 0,
"explicit": 1,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 687,
"album_id": 37641727,
"album_name": "BLAME IT ON BABY",
"artist_id": 45035319,
"artist_name": "DaBaby feat. Roddy Ricch",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/DaBaby-Roddy-Ricch\/ROCKSTAR-Roddy-Ricch?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/DaBaby-Roddy-Ricch\/ROCKSTAR-Roddy-Ricch\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-06-22T12:43:00Z",
"primary_genres": {
"music_genre_list": []
}
}
},
{
"track": {
"track_id": 200340862,
"track_name": "Patience",
"track_name_translation_list": [],
"track_rating": 98,
"commontrack_id": 113824017,
"instrumental": 0,
"explicit": 0,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 0,
"num_favourite": 4,
"album_id": 39273295,
"album_name": "Patience",
"artist_id": 156,
"artist_name": "Chris Cornell",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/Chris-Cornell\/Patience?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/Chris-Cornell\/Patience\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-07-21T20:15:22Z",
"primary_genres": {
"music_genre_list": []
}
}
},
{
"track": {
"track_id": 200360270,
"track_name": "Say Something",
"track_name_translation_list": [],
"track_rating": 1,
"commontrack_id": 113837622,
"instrumental": 0,
"explicit": 0,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 0,
"num_favourite": 0,
"album_id": 39278673,
"album_name": "DISCO (Deluxe)",
"artist_id": 7712,
"artist_name": "Kylie Minogue",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/Kylie-Minogue\/Say-Something?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/Kylie-Minogue\/Say-Something\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-07-23T16:04:00Z",
"primary_genres": {
"music_genre_list": [
{
"music_genre": {
"music_genre_id": 34,
"music_genre_parent_id": 0,
"music_genre_name": "Music",
"music_genre_name_extended": "Music",
"music_genre_vanity": "Music"
}
}
]
}
}
}
]
}
}
}
I used https://app.quicktype.io/ to get something like this:
// To parse this JSON data, do
//
// final jsonToDart = jsonToDartFromMap(jsonString);
import 'dart:convert';
JsonToDart jsonToDartFromMap(String str) => JsonToDart.fromMap(json.decode(str));
String jsonToDartToMap(JsonToDart data) => json.encode(data.toMap());
class JsonToDart {
JsonToDart({
this.message,
});
Message message;
factory JsonToDart.fromMap(Map<String, dynamic> json) => JsonToDart(
message: Message.fromMap(json["message"]),
);
Map<String, dynamic> toMap() => {
"message": message.toMap(),
};
}
class Message {
Message({
this.header,
this.body,
});
Header header;
Body body;
factory Message.fromMap(Map<String, dynamic> json) => Message(
header: Header.fromMap(json["header"]),
body: Body.fromMap(json["body"]),
);
Map<String, dynamic> toMap() => {
"header": header.toMap(),
"body": body.toMap(),
};
}
class Body {
Body({
this.trackList,
});
List<TrackList> trackList;
factory Body.fromMap(Map<String, dynamic> json) => Body(
trackList: List<TrackList>.from(json["track_list"].map((x) => TrackList.fromMap(x))),
);
Map<String, dynamic> toMap() => {
"track_list": List<dynamic>.from(trackList.map((x) => x.toMap())),
};
}
class TrackList {
TrackList({
this.track,
});
Track track;
factory TrackList.fromMap(Map<String, dynamic> json) => TrackList(
track: Track.fromMap(json["track"]),
);
Map<String, dynamic> toMap() => {
"track": track.toMap(),
};
}
class Track {
Track({
this.trackId,
this.trackName,
this.trackNameTranslationList,
this.trackRating,
this.commontrackId,
this.instrumental,
this.explicit,
this.hasLyrics,
this.hasSubtitles,
this.hasRichsync,
this.numFavourite,
this.albumId,
this.albumName,
this.artistId,
this.artistName,
this.trackShareUrl,
this.trackEditUrl,
this.restricted,
this.updatedTime,
this.primaryGenres,
});
int trackId;
String trackName;
List<dynamic> trackNameTranslationList;
int trackRating;
int commontrackId;
int instrumental;
int explicit;
int hasLyrics;
int hasSubtitles;
int hasRichsync;
int numFavourite;
int albumId;
String albumName;
int artistId;
String artistName;
String trackShareUrl;
String trackEditUrl;
int restricted;
DateTime updatedTime;
PrimaryGenres primaryGenres;
factory Track.fromMap(Map<String, dynamic> json) => Track(
trackId: json["track_id"],
trackName: json["track_name"],
trackNameTranslationList: List<dynamic>.from(json["track_name_translation_list"].map((x) => x)),
trackRating: json["track_rating"],
commontrackId: json["commontrack_id"],
instrumental: json["instrumental"],
explicit: json["explicit"],
hasLyrics: json["has_lyrics"],
hasSubtitles: json["has_subtitles"],
hasRichsync: json["has_richsync"],
numFavourite: json["num_favourite"],
albumId: json["album_id"],
albumName: json["album_name"],
artistId: json["artist_id"],
artistName: json["artist_name"],
trackShareUrl: json["track_share_url"],
trackEditUrl: json["track_edit_url"],
restricted: json["restricted"],
updatedTime: DateTime.parse(json["updated_time"]),
primaryGenres: PrimaryGenres.fromMap(json["primary_genres"]),
);
Map<String, dynamic> toMap() => {
"track_id": trackId,
"track_name": trackName,
"track_name_translation_list": List<dynamic>.from(trackNameTranslationList.map((x) => x)),
"track_rating": trackRating,
"commontrack_id": commontrackId,
"instrumental": instrumental,
"explicit": explicit,
"has_lyrics": hasLyrics,
"has_subtitles": hasSubtitles,
"has_richsync": hasRichsync,
"num_favourite": numFavourite,
"album_id": albumId,
"album_name": albumName,
"artist_id": artistId,
"artist_name": artistName,
"track_share_url": trackShareUrl,
"track_edit_url": trackEditUrl,
"restricted": restricted,
"updated_time": updatedTime.toIso8601String(),
"primary_genres": primaryGenres.toMap(),
};
}
class PrimaryGenres {
PrimaryGenres({
this.musicGenreList,
});
List<MusicGenreList> musicGenreList;
factory PrimaryGenres.fromMap(Map<String, dynamic> json) => PrimaryGenres(
musicGenreList: List<MusicGenreList>.from(json["music_genre_list"].map((x) => MusicGenreList.fromMap(x))),
);
Map<String, dynamic> toMap() => {
"music_genre_list": List<dynamic>.from(musicGenreList.map((x) => x.toMap())),
};
}
class MusicGenreList {
MusicGenreList({
this.musicGenre,
});
MusicGenre musicGenre;
factory MusicGenreList.fromMap(Map<String, dynamic> json) => MusicGenreList(
musicGenre: MusicGenre.fromMap(json["music_genre"]),
);
Map<String, dynamic> toMap() => {
"music_genre": musicGenre.toMap(),
};
}
class MusicGenre {
MusicGenre({
this.musicGenreId,
this.musicGenreParentId,
this.musicGenreName,
this.musicGenreNameExtended,
this.musicGenreVanity,
});
int musicGenreId;
int musicGenreParentId;
String musicGenreName;
String musicGenreNameExtended;
String musicGenreVanity;
factory MusicGenre.fromMap(Map<String, dynamic> json) => MusicGenre(
musicGenreId: json["music_genre_id"],
musicGenreParentId: json["music_genre_parent_id"],
musicGenreName: json["music_genre_name"],
musicGenreNameExtended: json["music_genre_name_extended"],
musicGenreVanity: json["music_genre_vanity"],
);
Map<String, dynamic> toMap() => {
"music_genre_id": musicGenreId,
"music_genre_parent_id": musicGenreParentId,
"music_genre_name": musicGenreName,
"music_genre_name_extended": musicGenreNameExtended,
"music_genre_vanity": musicGenreVanity,
};
}
class Header {
Header({
this.statusCode,
this.executeTime,
});
int statusCode;
double executeTime;
factory Header.fromMap(Map<String, dynamic> json) => Header(
statusCode: json["status_code"],
executeTime: json["execute_time"].toDouble(),
);
Map<String, dynamic> toMap() => {
"status_code": statusCode,
"execute_time": executeTime,
};
}
I used this in the main function:
Future<JsonToDart> getData() async {
var response = await http.get(url1);
print("ssssssssssssssss");
print(response.body);
return jsonToDartFromMap(response.body);
}
But I dont know how to proceed from here. I have to take the values of trackId,trackName,artistName,albumName and display in a listView.Many tutorials have different styles and this JSON data I just can't understand how to simplify it.Please help

Just check out the Example that I have created :
This is the json you provided
{
"message": {
"header": {
"status_code": 200,
"execute_time": 0.021989107131958
},
"body": {
"track_list": [
{
"track": {
"track_id": 200357565,
"track_name": "The Climb Back",
"track_name_translation_list": [],
"track_rating": 99,
"commontrack_id": 113835591,
"instrumental": 0,
"explicit": 1,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 20,
"album_id": 39278073,
"album_name": "Lewis Street",
"artist_id": 486280,
"artist_name": "J. Cole",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/J-Cole\/The-Climb-Back?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/J-Cole\/The-Climb-Back\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-07-23T14:02:17Z",
"primary_genres": {
"music_genre_list": []
}
}
},
{
"track": {
"track_id": 200187374,
"track_name": "POPSTAR (feat. Drake)",
"track_name_translation_list": [],
"track_rating": 99,
"commontrack_id": 113684105,
"instrumental": 0,
"explicit": 1,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 6,
"album_id": 39216808,
"album_name": "POPSTAR (feat. Drake) - Single",
"artist_id": 24704782,
"artist_name": "DJ Khaled feat. Drake, Lil Wayne & Rick Ross",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/DJ-Khaled-feat-Drake-Lil-Wayne-Rick-Ross\/POPSTAR-Drake?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/DJ-Khaled-feat-Drake-Lil-Wayne-Rick-Ross\/POPSTAR-Drake\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-07-17T13:38:30Z",
"primary_genres": {
"music_genre_list": []
}
}
},
{
"track": {
"track_id": 200102123,
"track_name": "What's Love Got to Do with It",
"track_name_translation_list": [],
"track_rating": 99,
"commontrack_id": 113606423,
"instrumental": 0,
"explicit": 0,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 18,
"album_id": 39186667,
"album_name": "What's Love Got to Do with It",
"artist_id": 45989671,
"artist_name": "Kygo feat. Tina Turner",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/Kygo-Tina-Turner\/What-s-Love-Got-to-Do-with-It?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/Kygo-Tina-Turner\/What-s-Love-Got-to-Do-with-It\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-07-23T06:28:49Z",
"primary_genres": {
"music_genre_list": []
}
}
},
{
"track": {
"track_id": 194169151,
"track_name": "Blinding Lights",
"track_name_translation_list": [],
"track_rating": 100,
"commontrack_id": 104185748,
"instrumental": 0,
"explicit": 0,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 5583,
"album_id": 37216011,
"album_name": "After Hours",
"artist_id": 13937035,
"artist_name": "The Weeknd",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/The-Weeknd-3\/Blinding-Lights?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/The-Weeknd-3\/Blinding-Lights\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-07-09T11:24:05Z",
"primary_genres": {
"music_genre_list": [
{
"music_genre": {
"music_genre_id": 7,
"music_genre_parent_id": 34,
"music_genre_name": "Electronic",
"music_genre_name_extended": "Electronic",
"music_genre_vanity": "Electronic"
}
}
]
}
}
},
{
"track": {
"track_id": 198421234,
"track_name": "Savage Love (Laxed - Siren Beat)",
"track_name_translation_list": [],
"track_rating": 100,
"commontrack_id": 112136372,
"instrumental": 0,
"explicit": 1,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 454,
"album_id": 38617941,
"album_name": "Savage Love (Laxed - Siren Beat) - Single",
"artist_id": 45643815,
"artist_name": "Jawsh 685 feat. Jason Derulo",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/Jawsh-685-Jason-Derulo\/Savage-Love-Laxed-Siren-Beat?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/Jawsh-685-Jason-Derulo\/Savage-Love-Laxed-Siren-Beat\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-07-09T13:06:43Z",
"primary_genres": {
"music_genre_list": []
}
}
},
{
"track": {
"track_id": 189626475,
"track_name": "Watermelon Sugar",
"track_name_translation_list": [],
"track_rating": 100,
"commontrack_id": 104939195,
"instrumental": 0,
"explicit": 0,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 567,
"album_id": 36101498,
"album_name": "Fine Line",
"artist_id": 24505463,
"artist_name": "Harry Styles",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/Harry-Styles\/Watermelon-Sugar-2?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/Harry-Styles\/Watermelon-Sugar-2\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2019-12-12T16:57:16Z",
"primary_genres": {
"music_genre_list": []
}
}
},
{
"track": {
"track_id": 192324206,
"track_name": "One Margarita",
"track_name_translation_list": [],
"track_rating": 99,
"commontrack_id": 107705631,
"instrumental": 0,
"explicit": 0,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 62,
"album_id": 36710192,
"album_name": "Born Here Live Here Die Here",
"artist_id": 360257,
"artist_name": "Luke Bryan",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/Luke-Bryan\/One-Margarita?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/Luke-Bryan\/One-Margarita\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-03-13T08:54:41Z",
"primary_genres": {
"music_genre_list": [
{
"music_genre": {
"music_genre_id": 34,
"music_genre_parent_id": 0,
"music_genre_name": "Music",
"music_genre_name_extended": "Music",
"music_genre_vanity": "Music"
}
}
]
}
}
},
{
"track": {
"track_id": 195445553,
"track_name": "ROCKSTAR (feat. Roddy Ricch)",
"track_name_translation_list": [],
"track_rating": 99,
"commontrack_id": 109586143,
"instrumental": 0,
"explicit": 1,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 1,
"num_favourite": 687,
"album_id": 37641727,
"album_name": "BLAME IT ON BABY",
"artist_id": 45035319,
"artist_name": "DaBaby feat. Roddy Ricch",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/DaBaby-Roddy-Ricch\/ROCKSTAR-Roddy-Ricch?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/DaBaby-Roddy-Ricch\/ROCKSTAR-Roddy-Ricch\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-06-22T12:43:00Z",
"primary_genres": {
"music_genre_list": []
}
}
},
{
"track": {
"track_id": 200340862,
"track_name": "Patience",
"track_name_translation_list": [],
"track_rating": 98,
"commontrack_id": 113824017,
"instrumental": 0,
"explicit": 0,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 0,
"num_favourite": 4,
"album_id": 39273295,
"album_name": "Patience",
"artist_id": 156,
"artist_name": "Chris Cornell",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/Chris-Cornell\/Patience?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/Chris-Cornell\/Patience\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-07-21T20:15:22Z",
"primary_genres": {
"music_genre_list": []
}
}
},
{
"track": {
"track_id": 200360270,
"track_name": "Say Something",
"track_name_translation_list": [],
"track_rating": 1,
"commontrack_id": 113837622,
"instrumental": 0,
"explicit": 0,
"has_lyrics": 1,
"has_subtitles": 1,
"has_richsync": 0,
"num_favourite": 0,
"album_id": 39278673,
"album_name": "DISCO (Deluxe)",
"artist_id": 7712,
"artist_name": "Kylie Minogue",
"track_share_url": "https:\/\/www.musixmatch.com\/lyrics\/Kylie-Minogue\/Say-Something?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"track_edit_url": "https:\/\/www.musixmatch.com\/lyrics\/Kylie-Minogue\/Say-Something\/edit?utm_source=application&utm_campaign=api&utm_medium=n%2Fa%3A1409620463618",
"restricted": 0,
"updated_time": "2020-07-23T16:04:00Z",
"primary_genres": {
"music_genre_list": [
{
"music_genre": {
"music_genre_id": 34,
"music_genre_parent_id": 0,
"music_genre_name": "Music",
"music_genre_name_extended": "Music",
"music_genre_vanity": "Music"
}
}
]
}
}
}
]
}
}
}
This is the model for the json :
// To parse this JSON data, do
//
// final track = trackFromJson(jsonString);
import 'dart:convert';
Track trackFromJson(String str) => Track.fromJson(json.decode(str));
String trackToJson(Track data) => json.encode(data.toJson());
class Track {
Track({
this.message,
});
Message message;
factory Track.fromJson(Map<String, dynamic> json) => Track(
message: Message.fromJson(json["message"]),
);
Map<String, dynamic> toJson() => {
"message": message.toJson(),
};
}
class Message {
Message({
this.header,
this.body,
});
Header header;
Body body;
factory Message.fromJson(Map<String, dynamic> json) => Message(
header: Header.fromJson(json["header"]),
body: Body.fromJson(json["body"]),
);
Map<String, dynamic> toJson() => {
"header": header.toJson(),
"body": body.toJson(),
};
}
class Body {
Body({
this.trackList,
});
List<TrackList> trackList;
factory Body.fromJson(Map<String, dynamic> json) => Body(
trackList: List<TrackList>.from(json["track_list"].map((x) => TrackList.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"track_list": List<dynamic>.from(trackList.map((x) => x.toJson())),
};
}
class TrackList {
TrackList({
this.track,
});
TrackClass track;
factory TrackList.fromJson(Map<String, dynamic> json) => TrackList(
track: TrackClass.fromJson(json["track"]),
);
Map<String, dynamic> toJson() => {
"track": track.toJson(),
};
}
class TrackClass {
TrackClass({
this.trackId,
this.trackName,
this.trackNameTranslationList,
this.trackRating,
this.commontrackId,
this.instrumental,
this.explicit,
this.hasLyrics,
this.hasSubtitles,
this.hasRichsync,
this.numFavourite,
this.albumId,
this.albumName,
this.artistId,
this.artistName,
this.trackShareUrl,
this.trackEditUrl,
this.restricted,
this.updatedTime,
this.primaryGenres,
});
int trackId;
String trackName;
List<dynamic> trackNameTranslationList;
int trackRating;
int commontrackId;
int instrumental;
int explicit;
int hasLyrics;
int hasSubtitles;
int hasRichsync;
int numFavourite;
int albumId;
String albumName;
int artistId;
String artistName;
String trackShareUrl;
String trackEditUrl;
int restricted;
DateTime updatedTime;
PrimaryGenres primaryGenres;
factory TrackClass.fromJson(Map<String, dynamic> json) => TrackClass(
trackId: json["track_id"],
trackName: json["track_name"],
trackNameTranslationList: List<dynamic>.from(json["track_name_translation_list"].map((x) => x)),
trackRating: json["track_rating"],
commontrackId: json["commontrack_id"],
instrumental: json["instrumental"],
explicit: json["explicit"],
hasLyrics: json["has_lyrics"],
hasSubtitles: json["has_subtitles"],
hasRichsync: json["has_richsync"],
numFavourite: json["num_favourite"],
albumId: json["album_id"],
albumName: json["album_name"],
artistId: json["artist_id"],
artistName: json["artist_name"],
trackShareUrl: json["track_share_url"],
trackEditUrl: json["track_edit_url"],
restricted: json["restricted"],
updatedTime: DateTime.parse(json["updated_time"]),
primaryGenres: PrimaryGenres.fromJson(json["primary_genres"]),
);
Map<String, dynamic> toJson() => {
"track_id": trackId,
"track_name": trackName,
"track_name_translation_list": List<dynamic>.from(trackNameTranslationList.map((x) => x)),
"track_rating": trackRating,
"commontrack_id": commontrackId,
"instrumental": instrumental,
"explicit": explicit,
"has_lyrics": hasLyrics,
"has_subtitles": hasSubtitles,
"has_richsync": hasRichsync,
"num_favourite": numFavourite,
"album_id": albumId,
"album_name": albumName,
"artist_id": artistId,
"artist_name": artistName,
"track_share_url": trackShareUrl,
"track_edit_url": trackEditUrl,
"restricted": restricted,
"updated_time": updatedTime.toIso8601String(),
"primary_genres": primaryGenres.toJson(),
};
}
class PrimaryGenres {
PrimaryGenres({
this.musicGenreList,
});
List<MusicGenreList> musicGenreList;
factory PrimaryGenres.fromJson(Map<String, dynamic> json) => PrimaryGenres(
musicGenreList: List<MusicGenreList>.from(json["music_genre_list"].map((x) => MusicGenreList.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"music_genre_list": List<dynamic>.from(musicGenreList.map((x) => x.toJson())),
};
}
class MusicGenreList {
MusicGenreList({
this.musicGenre,
});
MusicGenre musicGenre;
factory MusicGenreList.fromJson(Map<String, dynamic> json) => MusicGenreList(
musicGenre: MusicGenre.fromJson(json["music_genre"]),
);
Map<String, dynamic> toJson() => {
"music_genre": musicGenre.toJson(),
};
}
class MusicGenre {
MusicGenre({
this.musicGenreId,
this.musicGenreParentId,
this.musicGenreName,
this.musicGenreNameExtended,
this.musicGenreVanity,
});
int musicGenreId;
int musicGenreParentId;
String musicGenreName;
String musicGenreNameExtended;
String musicGenreVanity;
factory MusicGenre.fromJson(Map<String, dynamic> json) => MusicGenre(
musicGenreId: json["music_genre_id"],
musicGenreParentId: json["music_genre_parent_id"],
musicGenreName: json["music_genre_name"],
musicGenreNameExtended: json["music_genre_name_extended"],
musicGenreVanity: json["music_genre_vanity"],
);
Map<String, dynamic> toJson() => {
"music_genre_id": musicGenreId,
"music_genre_parent_id": musicGenreParentId,
"music_genre_name": musicGenreName,
"music_genre_name_extended": musicGenreNameExtended,
"music_genre_vanity": musicGenreVanity,
};
}
class Header {
Header({
this.statusCode,
this.executeTime,
});
int statusCode;
double executeTime;
factory Header.fromJson(Map<String, dynamic> json) => Header(
statusCode: json["status_code"],
executeTime: json["execute_time"].toDouble(),
);
Map<String, dynamic> toJson() => {
"status_code": statusCode,
"execute_time": executeTime,
};
}
This is the ui for the model:
import 'package:flutter/material.dart';
import 'package:json_parsing_example/models.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(home: HomePage());
}
}
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
List<TrackList> trackList = List();
bool _isLoading = false;
#override
void initState() {
super.initState();
getData();
}
getData() async {
setState(() {
_isLoading = true;
});
String data =
await DefaultAssetBundle.of(context).loadString("json/parse.json");
final track = trackFromJson(data);
trackList = track.message.body.trackList;
setState(() {
_isLoading = false;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: _isLoading
? Center(
child: CircularProgressIndicator(),
)
: ListView.builder(
itemCount: trackList.length,
itemBuilder: (context, index) {
var item = trackList[index];
return Card(
margin: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Track Id :' + item.track.trackId.toString()),
Text('Track Name:' + item.track.trackName.toString()),
Text(
'Artist Name :' + item.track.artistName.toString()),
Text('Album Name :' + item.track.albumName.toString())
],
),
);
}));
}
}
From the function what I see is you can do like this:
Future<List<TrackList>> getData() async {
var response = await http.get(url1);
print("ssssssssssssssss");
print(response.body);
var item = trackFromJson(response.body);
return item.body.track_list;
}
Check out the example and let me know if it works.

The way to do it is to create your own model classes in which you perform parsing mechanism. One of the examples would be user class created like this:
class User {
String firstName;
String lastName;
String phoneNumber;
String emailAddress;
User({
this.firstName,
this.lastName,
this.phoneNumber,
this.emailAddress,
});
factory User.fromJson(Map<String, dynamic> json) {
return User(
firstName: json["first_name"],
lastName: json["last_name"],
phoneNumber: json["phone_number"],
emailAddress: json["email_address"],
);
}
}
After you are done creating your base model that holds entire tree you posted above, you go ahead and start parsing array elements such as track_list by creating Track model listing all the track properties. Once you have your base model, Track model and all the properties of the Track model, you would need to link that track list to your base model and it's done like this:
List jsonList = json.decode(serverResponse.body)['track_list'];
trackList: List.generate(jsonList.length, (i) => Track.fromJson(jsonList[i]));
When you complete linking base model, list of tracks and parsing of a single track, you will also need to parse inner Track lists in the same way, but basics of the parsing mechanism I listed above should be enough to get you through the entire process of parsing JSON object and JSON inner list objects.

Related

type '(dynamic) => SBranch' is not a subtype of type '(String, dynamic) => MapEntry<dynamic, dynamic>' of 'transform

I have tried several ways to access the data but the result is still the same where the type is a map and I can't convert it to a list of my model so I hope to get some help and I am thankful to you
my Repo
Future getdata(apiUrl) async {
http.Response response = await http.get(Uri.parse(_url + apiUrl));
try {
if (response.statusCode == 200) {
print('dtaa serve done 200');
var body= jsonDecode(response.body);
print(body.runtimeType);
print(body.runtimeType);
return body;
} else {
print("its empty first");
return {};
}
} catch (e) {
print(e.toString() + "first");
return {};
}
my Cubit
void getSBranchData(Service service) async {
try { print("loding SBranchData");
sBranches = await repo.getSBranches(service.id);
print(sBranches.toString()+" Cubit");
emit(SBranchDataState(sBranches,service));
print("loded SBranchData");
} catch (e) {
print(e.toString() + "sec");
}
is this Right
my model
SBranch(
{this.id,
this.sbranchName,
this.sbranchDisc,
this.sbranchImg,
this.parentSbranch,
this.serviceId,
this.childSbranch});
SBranch.fromJson(Map<String, dynamic> json) {
id = json['id'];
sbranchName = json['sbranch_name'];
sbranchDisc = json['sbranch_disc'];
sbranchImg = json['sbranch_img'];
parentSbranch = json['parent_sbranch'];
serviceId = json['service_id'];
if (json['child_sbranch'] != null) {
childSbranch = <ChildSbranch>[];
json['child_sbranch'].forEach((v) {
childSbranch!.add(new ChildSbranch.fromJson(v));
});
json
[
{
"id": 1,
"sbranch_name": "mn,.m.",
"sbranch_disc": "lmlmlm.",
"sbranch_img": "",
"parent_sbranch": 0,
"service_id": "1",
"child_sbranch": [
{
"id": 3,
"sbranch_name": "mn,.m.",
"sbranch_disc": "lmlmlm.",
"sbranch_img": "",
"parent_sbranch": 1,
"service_id": "",
"child_sbranch": []
}
]
},
{
"id": 2,
"sbranch_name": "mn,.m.",
"sbranch_disc": "lmlmlm.",
"sbranch_img": "",
"parent_sbranch": 0,
"service_id": "2",
"child_sbranch": [
{
"id": 4,
"sbranch_name": "mn,.m.",
"sbranch_disc": "lmlmlm.",
"sbranch_img": "",
"parent_sbranch": 2,
"service_id": "",
"child_sbranch": []
}
]
},
{
"id": 3,
"sbranch_name": "mn,.m.",
"sbranch_disc": "lmlmlm.",
"sbranch_img": "",
"parent_sbranch": 1,
"service_id": "",
"child_sbranch": []
},
{
"id": 4,
"sbranch_name": "mn,.m.",
"sbranch_disc": "lmlmlm.",
"sbranch_img": "",
"parent_sbranch": 2,
"service_id": "",
"child_sbranch": []
}
]
thanks for your Time
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv** *
v*

How to display JSON data which is in Array list format

I need a quick help for the syntax to display JSON data which are in array list format(I guess)
I'm able to display Status & Message but struggling with syntax when I want to display Name Image which are inside Data[]. What syntax I should use to display those data ?
My JSON response
{
"Status": "1",
"Message": "3 records found.",
"Data": [
{
"Name": "Brain surgery",
"EncId": "B909+U0FIAHIs+sl3IYTvQ==",
"Image": "",
"Extra1": "abdsjh dsgjhgdd gsjjkdkds dddsjkhdj djdjkdh dshjdkhkd dhdhdk sjkghdjkdhkhd dhkdkhdkjhd hkjhkdhd kdjkdjdkjd dhkdkjhdjh ddkdkhd dhdhhd . dgjgdjd dgdgjds",
"Extra2": "",
"ResultFor": "p6r4bAAI4ybdJySoV+PqGQ=="
},
{
"Name": "Dr Ram Das",
"EncId": "fXVmzecGStqrhx1PmIgwlQ==",
"Image": "http://medbo.digitalicon.in/Doctor/U7MK2MZGD0QVQ7E8IR7N.jpg",
"Extra1": "ENT",
"Extra2": "kj",
"ResultFor": "xPCleDOirQpArdOv0uUR9g=="
},
{
"Name": "Kidney Routine Test with Sonography and Serology.",
"EncId": "U4exk+vfMGrn7cjNUa/PBw==",
"Image": "",
"Extra1": "",
"Extra2": "",
"ResultFor": "aZsjjLg3WIBbTg05/15o2w=="
}
]
}
My model class
class SearchApiResponse {
SearchApiResponse({
required this.status,
required this.message,
required this.data,
});
String status;
String message;
List<SearchData> data;
factory SearchApiResponse.fromJson(Map<String, dynamic> json) => SearchApiResponse(
status: json["Status"],
message: json["Message"],
data: List<SearchData>.from(json["Data"].map((x) => SearchData.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"Status": status,
"Message": message,
"Data": List<dynamic>.from(data.map((x) => x.toJson())),
};
}
class SearchData {
SearchData({
required this.name,
required this.encId,
required this.image,
required this.extra1,
required this.extra2,
required this.resultFor,
});
String name;
String encId;
String image;
String extra1;
String extra2;
String resultFor;
factory SearchData.fromJson(Map<String, dynamic> json) => SearchData(
name: json["Name"],
encId: json["EncId"],
image: json["Image"],
extra1: json["Extra1"],
extra2: json["Extra2"],
resultFor: json["ResultFor"],
);
Map<String, dynamic> toJson() => {
"Name": name,
"EncId": encId,
"Image": image,
"Extra1": extra1,
"Extra2": extra2,
"ResultFor": resultFor,
};
}
And Here I can successfully display Status & the message but how to display others which are inside Data[] ?
class AfterSearchPage extends StatefulWidget {
final SearchApiResponse rresponse;
const AfterSearchPage({required this.rresponse});
#override
_AfterSearchPageState createState() => _AfterSearchPageState();
}
class _AfterSearchPageState extends State<AfterSearchPage> {
var responseRef;
// _SecondState(this.responseRef);
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Status: ${widget.rresponse.status}"),
Text("Message: ${widget.rresponse.message}"),
Text("Name: ${widget.rresponse.data.name}"),//==??????????????????????????????????????Error
SizedBox(
height: 50,
),
OutlinedButton.icon(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Home2(),
),
);
},
icon: Icon(
Icons.exit_to_app,
size: 18,
),
label: Text("GoTo Home")),
],
),
),
),
);
}
}
Data is an array, so you need to address it as such.
for (var d in folder.data) {
print(d.name);
}
Here's a sample project to show you that:
import 'dart:convert';
void main() {
final folder = Folder.fromJson(json.decode('''{
"Status": "1",
"Message": "3 records found.",
"Data": [
{
"Name": "Brain surgery",
"EncId": "B909+U0FIAHIs+sl3IYTvQ==",
"Image": "",
"Extra1": "abdsjh dsgjhgdd gsjjkdkds dddsjkhdj djdjkdh dshjdkhkd dhdhdk sjkghdjkdhkhd dhkdkhdkjhd hkjhkdhd kdjkdjdkjd dhkdkjhdjh ddkdkhd dhdhhd . dgjgdjd dgdgjds",
"Extra2": "",
"ResultFor": "p6r4bAAI4ybdJySoV+PqGQ=="
},
{
"Name": "Dr Ram Das",
"EncId": "fXVmzecGStqrhx1PmIgwlQ==",
"Image": "http://medbo.digitalicon.in/Doctor/U7MK2MZGD0QVQ7E8IR7N.jpg",
"Extra1": "ENT",
"Extra2": "kj",
"ResultFor": "xPCleDOirQpArdOv0uUR9g=="
},
{
"Name": "Kidney Routine Test with Sonography and Serology.",
"EncId": "U4exk+vfMGrn7cjNUa/PBw==",
"Image": "",
"Extra1": "",
"Extra2": "",
"ResultFor": "aZsjjLg3WIBbTg05/15o2w=="
}
]
}'''));
print(folder.status);
print(folder.message);
for (var d in folder.data) {
print(d.name);
}
}
class Folder {
Folder({
this.status,
this.message,
this.data,
});
String status;
String message;
List<Data> data;
factory Folder.fromJson(Map<String, dynamic> json) => Folder(
status: json["Status"],
message: json["Message"],
data: List<Data>.from(json["Data"].map((x) => Data.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"Status": status,
"Message": message,
"Data": List<dynamic>.from(data.map((x) => x.toJson())),
};
}
class Data {
Data({
this.name,
this.encId,
this.image,
this.extra1,
this.extra2,
this.resultFor,
});
String name;
String encId;
String image;
String extra1;
String extra2;
String resultFor;
factory Data.fromJson(Map<String, dynamic> json) => Data(
name: json["Name"],
encId: json["EncId"],
image: json["Image"],
extra1: json["Extra1"],
extra2: json["Extra2"],
resultFor: json["ResultFor"],
);
Map<String, dynamic> toJson() => {
"Name": name,
"EncId": encId,
"Image": image,
"Extra1": extra1,
"Extra2": extra2,
"ResultFor": resultFor,
};
}
You can test this code in dartpad: https://dartpad.dartlang.org
just give the index number
Text("Name: ${widget.rresponse.data[0].name}")

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

Future<List<CurrentUser>> getCurrUserSettings() async {
int id = await getCurrentUser();
print(id);
final _storage = FlutterSecureStorage();
_token = await _storage.read(key: "token");
var api = API();
// TODO resolve id so that we have it on the start and not called everytime
String newUrl = "${api.baseUrl}${api.cuUser}$id";
var url = Uri.parse(newUrl);
var response = await http.get(
url,
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': "Bearer $_token",
},
);
if (response.statusCode == 200) {
final parsed = jsonDecode(response.body).cast<Map<String, dynamic>>();
return parsed
.map<CurrentUser>((json) => CurrentUser.fromJson(json))
.toList();
} else {
print(response.statusCode);
}
return null; }
This is the code I am using to call current user data. This function returns a list. I have made many other API calls with the same technique and all of them are working perfectly fine but only in this method I am getting the following error.
E/flutter (14954): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'cast' with matching arguments.
E/flutter (14954): Receiver: _LinkedHashMap len:16
E/flutter (14954): Tried calling: cast<Map<String, dynamic>>()
E/flutter (14954): Found: cast<RK, RV>() => Map<RK, RV>
E/flutter (14954): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
E/flutter (14954): #1 AuthService.getCurrUserSettings
package:App/…/Services/Auth.dart:73
E/flutter (14954): <asynchronous suspension>
E/flutter (14954): #2 DrawerUserInfo.getUserInfo
package:App/…/components/drawerProvider.dart:10
E/flutter (14954): <asynchronous suspension>
I am also sharing the model file too please take a look. I am stuck with this for a while I have used many different models and the error is same in every model.
Response Json
{
"id": 3,
"username": "PlayPizza",
"email": "play#pizza.com",
"provider": "local",
"confirmed": true,
"blocked": null,
"role": {
"id": 1,
"name": "Authenticated",
"description": "Default role given to authenticated user.",
"type": "authenticated"
},
"displayName": "PlayPizza",
"user_information": {
"id": 1,
"country": "India",
"state": "Delhi",
"address": "Some address",
"postalcode": "110092",
"users_permissions_user": 3,
"published_at": "2021-07-04T21:24:46.324Z",
"created_at": "2021-07-04T21:24:43.063Z",
"updated_at": "2021-07-04T21:24:46.409Z",
"certificate": {
"id": 1,
"name": "1_9cb3b3b033.jpg",
"alternativeText": "",
"caption": "",
"width": 300,
"height": 300,
"formats": {
"thumbnail": {
"ext": ".jpg",
"url": "/uploads/thumbnail_1_9cb3b3b033_7980eea4f5.jpg",
"hash": "thumbnail_1_9cb3b3b033_7980eea4f5",
"mime": "image/jpeg",
"name": "thumbnail_1_9cb3b3b033.jpg",
"path": null,
"size": 2.48,
"width": 156,
"height": 156
}
},
"hash": "1_9cb3b3b033_7980eea4f5",
"ext": ".jpg",
"mime": "image/jpeg",
"size": 5.28,
"url": "/uploads/1_9cb3b3b033_7980eea4f5.jpg",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"created_at": "2021-07-04T15:03:55.744Z",
"updated_at": "2021-07-04T15:03:55.798Z"
}
},
"feedback": "hello",
"created_at": "2021-07-04T19:59:30.024Z",
"updated_at": "2021-07-04T21:26:41.314Z",
"avatar": {
"id": 10,
"name": "customer_3_008140d19d.png",
"alternativeText": "",
"caption": "",
"width": 180,
"height": 180,
"formats": {
"thumbnail": {
"ext": ".png",
"url": "/uploads/thumbnail_customer_3_008140d19d_a96cc0a5e3.png",
"hash": "thumbnail_customer_3_008140d19d_a96cc0a5e3",
"mime": "image/png",
"name": "thumbnail_customer_3_008140d19d.png",
"path": null,
"size": 62.71,
"width": 156,
"height": 156
}
},
"hash": "customer_3_008140d19d_a96cc0a5e3",
"ext": ".png",
"mime": "image/png",
"size": 65.81,
"url": "/uploads/customer_3_008140d19d_a96cc0a5e3.png",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"created_at": "2021-07-04T17:59:44.000Z",
"updated_at": "2021-07-04T17:59:44.024Z"
},
"user_categories": [
{
"id": 1,
"categoryName": "GymGoer",
"users_permissions_user": 3,
"published_at": "2021-07-04T15:53:43.824Z",
"created_at": "2021-07-04T15:53:39.228Z",
"updated_at": "2021-07-04T21:26:41.307Z"
}
],
"workoutplaces": [
{
"id": 2,
"title": "Gym Nation",
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
"location": "145 Marlee Ave, York, ON M6B 3H3, Canada",
"price": 88.26,
"rating": 4.5,
"latitude": 43.80946617910369,
"longitude": -79.26975142707997,
"users_permissions_user": 3,
"published_at": "2021-07-04T17:09:53.162Z",
"created_at": "2021-07-04T17:09:50.238Z",
"updated_at": "2021-07-04T21:26:41.308Z",
"coverimg": {
"id": 8,
"name": "large_sule_makaroglu_Y_Fmvj_O3_TP_s_unsplash_c546ce68c3.jpg",
"alternativeText": "",
"caption": "",
"width": 1000,
"height": 666,
"formats": {
"small": {
"ext": ".jpg",
"url": "/uploads/small_large_sule_makaroglu_Y_Fmvj_O3_TP_s_unsplash_c546ce68c3_fe08736916.jpg",
"hash": "small_large_sule_makaroglu_Y_Fmvj_O3_TP_s_unsplash_c546ce68c3_fe08736916",
"mime": "image/jpeg",
"name": "small_large_sule_makaroglu_Y_Fmvj_O3_TP_s_unsplash_c546ce68c3.jpg",
"path": null,
"size": 27.34,
"width": 500,
"height": 333
},
"medium": {
"ext": ".jpg",
"url": "/uploads/medium_large_sule_makaroglu_Y_Fmvj_O3_TP_s_unsplash_c546ce68c3_fe08736916.jpg",
"hash": "medium_large_sule_makaroglu_Y_Fmvj_O3_TP_s_unsplash_c546ce68c3_fe08736916",
"mime": "image/jpeg",
"name": "medium_large_sule_makaroglu_Y_Fmvj_O3_TP_s_unsplash_c546ce68c3.jpg",
"path": null,
"size": 48.79,
"width": 750,
"height": 500
},
"thumbnail": {
"ext": ".jpg",
"url": "/uploads/thumbnail_large_sule_makaroglu_Y_Fmvj_O3_TP_s_unsplash_c546ce68c3_fe08736916.jpg",
"hash": "thumbnail_large_sule_makaroglu_Y_Fmvj_O3_TP_s_unsplash_c546ce68c3_fe08736916",
"mime": "image/jpeg",
"name": "thumbnail_large_sule_makaroglu_Y_Fmvj_O3_TP_s_unsplash_c546ce68c3.jpg",
"path": null,
"size": 9.3,
"width": 234,
"height": 156
}
},
"hash": "large_sule_makaroglu_Y_Fmvj_O3_TP_s_unsplash_c546ce68c3_fe08736916",
"ext": ".jpg",
"mime": "image/jpeg",
"size": 74.23,
"url": "/uploads/large_sule_makaroglu_Y_Fmvj_O3_TP_s_unsplash_c546ce68c3_fe08736916.jpg",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"created_at": "2021-07-04T17:05:47.094Z",
"updated_at": "2021-07-04T17:05:47.104Z"
}
}
],
"upcomming_classes": [
{
"id": 1,
"name": "Yoga house",
"description": "Some Description",
"date": "2021-07-13",
"time": "01:30:00",
"confirmed": true,
"paid": true,
"price": 59.33,
"workoutplace": 1,
"users_permissions_user": 3,
"month": "July",
"published_at": null,
"created_at": "2021-07-04T21:26:23.276Z",
"updated_at": "2021-07-04T21:26:41.309Z"
}
]}
Model File
import 'dart:convert';
CurrentUser currentUserFromJson(String str) =>
CurrentUser.fromJson(json.decode(str));
String currentUserToJson(CurrentUser data) => json.encode(data.toJson());
class CurrentUser {
CurrentUser({
this.id,
this.username,
this.email,
this.provider,
this.confirmed,
this.blocked,
this.role,
this.displayName,
this.userInformation,
this.feedback,
this.createdAt,
this.updatedAt,
this.avatar,
this.userCategories,
this.workoutplaces,
this.upcommingClasses,
});
int id;
String username;
String email;
String provider;
bool confirmed;
dynamic blocked;
Role role;
String displayName;
UserInformation userInformation;
String feedback;
DateTime createdAt;
DateTime updatedAt;
Avatar avatar;
List<UserCategory> userCategories;
List<Workoutplace> workoutplaces;
List<UpcommingClass> upcommingClasses;
factory CurrentUser.fromJson(Map<String, dynamic> json) => CurrentUser(
id: json["id"],
username: json["username"],
email: json["email"],
provider: json["provider"],
confirmed: json["confirmed"],
blocked: json["blocked"],
role: Role.fromJson(json["role"]),
displayName: json["displayName"],
userInformation: UserInformation.fromJson(json["user_information"]),
feedback: json["feedback"],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
avatar: Avatar.fromJson(json["avatar"]),
userCategories: List<UserCategory>.from(
json["user_categories"].map((x) => UserCategory.fromJson(x))),
workoutplaces: List<Workoutplace>.from(
json["workoutplaces"].map((x) => Workoutplace.fromJson(x))),
upcommingClasses: List<UpcommingClass>.from(
json["upcomming_classes"].map((x) => UpcommingClass.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"id": id,
"username": username,
"email": email,
"provider": provider,
"confirmed": confirmed,
"blocked": blocked,
"role": role.toJson(),
"displayName": displayName,
"user_information": userInformation.toJson(),
"feedback": feedback,
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
"avatar": avatar.toJson(),
"user_categories":
List<dynamic>.from(userCategories.map((x) => x.toJson())),
"workoutplaces":
List<dynamic>.from(workoutplaces.map((x) => x.toJson())),
"upcomming_classes":
List<dynamic>.from(upcommingClasses.map((x) => x.toJson())),
};
}
class Avatar {
Avatar({
this.id,
this.name,
this.alternativeText,
this.caption,
this.width,
this.height,
this.formats,
this.hash,
this.ext,
this.mime,
this.size,
this.url,
this.previewUrl,
this.provider,
this.providerMetadata,
this.createdAt,
this.updatedAt,
});
int id;
String name;
String alternativeText;
String caption;
int width;
int height;
AvatarFormats formats;
String hash;
String ext;
String mime;
double size;
String url;
dynamic previewUrl;
String provider;
dynamic providerMetadata;
DateTime createdAt;
DateTime updatedAt;
factory Avatar.fromJson(Map<String, dynamic> json) => Avatar(
id: json["id"],
name: json["name"],
alternativeText: json["alternativeText"],
caption: json["caption"],
width: json["width"],
height: json["height"],
formats: AvatarFormats.fromJson(json["formats"]),
hash: json["hash"],
ext: json["ext"],
mime: json["mime"],
size: json["size"].toDouble(),
url: json["url"],
previewUrl: json["previewUrl"],
provider: json["provider"],
providerMetadata: json["provider_metadata"],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"alternativeText": alternativeText,
"caption": caption,
"width": width,
"height": height,
"formats": formats.toJson(),
"hash": hash,
"ext": ext,
"mime": mime,
"size": size,
"url": url,
"previewUrl": previewUrl,
"provider": provider,
"provider_metadata": providerMetadata,
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
};
}
class AvatarFormats {
AvatarFormats({
this.thumbnail,
});
Thumbnail thumbnail;
factory AvatarFormats.fromJson(Map<String, dynamic> json) => AvatarFormats(
thumbnail: Thumbnail.fromJson(json["thumbnail"]),
);
Map<String, dynamic> toJson() => {
"thumbnail": thumbnail.toJson(),
};
}
class Thumbnail {
Thumbnail({
this.ext,
this.url,
this.hash,
this.mime,
this.name,
this.path,
this.size,
this.width,
this.height,
});
String ext;
String url;
String hash;
String mime;
String name;
dynamic path;
double size;
int width;
int height;
factory Thumbnail.fromJson(Map<String, dynamic> json) => Thumbnail(
ext: json["ext"],
url: json["url"],
hash: json["hash"],
mime: json["mime"],
name: json["name"],
path: json["path"],
size: json["size"].toDouble(),
width: json["width"],
height: json["height"],
);
Map<String, dynamic> toJson() => {
"ext": ext,
"url": url,
"hash": hash,
"mime": mime,
"name": name,
"path": path,
"size": size,
"width": width,
"height": height,
};
}
class Role {
Role({
this.id,
this.name,
this.description,
this.type,
});
int id;
String name;
String description;
String type;
factory Role.fromJson(Map<String, dynamic> json) => Role(
id: json["id"],
name: json["name"],
description: json["description"],
type: json["type"],
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"description": description,
"type": type,
};
}
class UpcommingClass {
UpcommingClass({
this.id,
this.name,
this.description,
this.date,
this.time,
this.confirmed,
this.paid,
this.price,
this.workoutplace,
this.usersPermissionsUser,
this.month,
this.publishedAt,
this.createdAt,
this.updatedAt,
});
int id;
String name;
String description;
DateTime date;
String time;
bool confirmed;
bool paid;
double price;
int workoutplace;
int usersPermissionsUser;
String month;
dynamic publishedAt;
DateTime createdAt;
DateTime updatedAt;
factory UpcommingClass.fromJson(Map<String, dynamic> json) => UpcommingClass(
id: json["id"],
name: json["name"],
description: json["description"],
date: DateTime.parse(json["date"]),
time: json["time"],
confirmed: json["confirmed"],
paid: json["paid"],
price: json["price"].toDouble(),
workoutplace: json["workoutplace"],
usersPermissionsUser: json["users_permissions_user"],
month: json["month"],
publishedAt: json["published_at"],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"description": description,
"date":
"${date.year.toString().padLeft(4, '0')}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}",
"time": time,
"confirmed": confirmed,
"paid": paid,
"price": price,
"workoutplace": workoutplace,
"users_permissions_user": usersPermissionsUser,
"month": month,
"published_at": publishedAt,
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
};
}
class UserCategory {
UserCategory({
this.id,
this.categoryName,
this.usersPermissionsUser,
this.publishedAt,
this.createdAt,
this.updatedAt,
});
int id;
String categoryName;
int usersPermissionsUser;
DateTime publishedAt;
DateTime createdAt;
DateTime updatedAt;
factory UserCategory.fromJson(Map<String, dynamic> json) => UserCategory(
id: json["id"],
categoryName: json["categoryName"],
usersPermissionsUser: json["users_permissions_user"],
publishedAt: DateTime.parse(json["published_at"]),
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
);
Map<String, dynamic> toJson() => {
"id": id,
"categoryName": categoryName,
"users_permissions_user": usersPermissionsUser,
"published_at": publishedAt.toIso8601String(),
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
};
}
class UserInformation {
UserInformation({
this.id,
this.country,
this.state,
this.address,
this.postalcode,
this.usersPermissionsUser,
this.publishedAt,
this.createdAt,
this.updatedAt,
this.certificate,
});
int id;
String country;
String state;
String address;
String postalcode;
int usersPermissionsUser;
DateTime publishedAt;
DateTime createdAt;
DateTime updatedAt;
Avatar certificate;
factory UserInformation.fromJson(Map<String, dynamic> json) =>
UserInformation(
id: json["id"],
country: json["country"],
state: json["state"],
address: json["address"],
postalcode: json["postalcode"],
usersPermissionsUser: json["users_permissions_user"],
publishedAt: DateTime.parse(json["published_at"]),
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
certificate: Avatar.fromJson(json["certificate"]),
);
Map<String, dynamic> toJson() => {
"id": id,
"country": country,
"state": state,
"address": address,
"postalcode": postalcode,
"users_permissions_user": usersPermissionsUser,
"published_at": publishedAt.toIso8601String(),
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
"certificate": certificate.toJson(),
};
}
class Workoutplace {
Workoutplace({
this.id,
this.title,
this.description,
this.location,
this.price,
this.rating,
this.latitude,
this.longitude,
this.usersPermissionsUser,
this.publishedAt,
this.createdAt,
this.updatedAt,
this.coverimg,
});
int id;
String title;
String description;
String location;
double price;
double rating;
double latitude;
double longitude;
int usersPermissionsUser;
DateTime publishedAt;
DateTime createdAt;
DateTime updatedAt;
Coverimg coverimg;
factory Workoutplace.fromJson(Map<String, dynamic> json) => Workoutplace(
id: json["id"],
title: json["title"],
description: json["description"],
location: json["location"],
price: json["price"].toDouble(),
rating: json["rating"].toDouble(),
latitude: json["latitude"].toDouble(),
longitude: json["longitude"].toDouble(),
usersPermissionsUser: json["users_permissions_user"],
publishedAt: DateTime.parse(json["published_at"]),
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
coverimg: Coverimg.fromJson(json["coverimg"]),
);
Map<String, dynamic> toJson() => {
"id": id,
"title": title,
"description": description,
"location": location,
"price": price,
"rating": rating,
"latitude": latitude,
"longitude": longitude,
"users_permissions_user": usersPermissionsUser,
"published_at": publishedAt.toIso8601String(),
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
"coverimg": coverimg.toJson(),
};
}
class Coverimg {
Coverimg({
this.id,
this.name,
this.alternativeText,
this.caption,
this.width,
this.height,
this.formats,
this.hash,
this.ext,
this.mime,
this.size,
this.url,
this.previewUrl,
this.provider,
this.providerMetadata,
this.createdAt,
this.updatedAt,
});
int id;
String name;
String alternativeText;
String caption;
int width;
int height;
CoverimgFormats formats;
String hash;
String ext;
String mime;
double size;
String url;
dynamic previewUrl;
String provider;
dynamic providerMetadata;
DateTime createdAt;
DateTime updatedAt;
factory Coverimg.fromJson(Map<String, dynamic> json) => Coverimg(
id: json["id"],
name: json["name"],
alternativeText: json["alternativeText"],
caption: json["caption"],
width: json["width"],
height: json["height"],
formats: CoverimgFormats.fromJson(json["formats"]),
hash: json["hash"],
ext: json["ext"],
mime: json["mime"],
size: json["size"].toDouble(),
url: json["url"],
previewUrl: json["previewUrl"],
provider: json["provider"],
providerMetadata: json["provider_metadata"],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"alternativeText": alternativeText,
"caption": caption,
"width": width,
"height": height,
"formats": formats.toJson(),
"hash": hash,
"ext": ext,
"mime": mime,
"size": size,
"url": url,
"previewUrl": previewUrl,
"provider": provider,
"provider_metadata": providerMetadata,
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
};
}
class CoverimgFormats {
CoverimgFormats({
this.small,
this.medium,
this.thumbnail,
});
Thumbnail small;
Thumbnail medium;
Thumbnail thumbnail;
factory CoverimgFormats.fromJson(Map<String, dynamic> json) =>
CoverimgFormats(
small: Thumbnail.fromJson(json["small"]),
medium: Thumbnail.fromJson(json["medium"]),
thumbnail: Thumbnail.fromJson(json["thumbnail"]),
);
Map<String, dynamic> toJson() => {
"small": small.toJson(),
"medium": medium.toJson(),
"thumbnail": thumbnail.toJson(),
};
}
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);

Not able to parse json data in flutter

I am not able to parse below mentioned json data in flutter.
[
{
"id": 96,
"name": "Entertainment",
"link": "https://thehappilyeverafter.in/listing-category/entertainment/",
"image": "https://thehappilyeverafter.in/wp-content/uploads/2021/05/a685b39b20592b03c0939878edb0cb84.jpg",
"children": [
{
"child_id": 114,
"child_name": "DJs",
"child_link": "https://thehappilyeverafter.in/listing-category/djs/"
},
{
"child_id": 117,
"child_name": "Live Music",
"child_link": "https://thehappilyeverafter.in/listing-category/live-music/"
},
{
"child_id": 115,
"child_name": "Wedding Choreographer",
"child_link": "https://thehappilyeverafter.in/listing-category/wedding-choreographer/"
},
{
"child_id": 116,
"child_name": "Wedding Entertainment",
"child_link": "https://thehappilyeverafter.in/listing-category/wedding-entertainment/"
}
]
}
]`
import 'dart:convert';
List<Root> rootFromJson(String str) => List<Root>.from(json.decode(str).map((x) => Root.fromJson(x)));
String rootToJson(List<Root> data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
class Root {
Root({
this.id,
this.name,
this.link,
this.image,
this.children,
});
int id;
String name;
String link;
String image;
List<Children> children;
factory Root.fromJson(Map<String, dynamic> json) => Root(
id: json["id"],
name: json["name"],
link: json["link"],
image: json["image"] == null ? null : json["image"],
children: List<Children>.from(json["children"].map((x) => Children.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"link": link,
"image": image == null ? null : image,
"children": List<dynamic>.from(children.map((x) => x.toJson())),
};
}
class Children {
Children({
this.childId,
this.childName,
this.childLink,
});
int childId;
String childName;
String childLink;
factory Children.fromJson(Map<String, dynamic> json) => Children(
childId: json["child_id"],
childName: json["child_name"],
childLink: json["child_link"],
);
Map<String, dynamic> toJson() => {
"child_id": childId,
"child_name": childName,
"child_link": childLink,
};
}
[Getting this error][1]
`
type 'List' is not a subtype of type 'Children'
Since your json is a list, you should loop through it:
final List<Root> roots = yourJson.map((element) {
return Root.fromJson(element);
}).toList();
print(roots.first.image);
//https://thehappilyeverafter.in/wp-content/uploads/2021/05/a685b39b20592b03c0939878edb0cb84.jpg

Json Model Class has no getter list receiver instance

Simple JSON data fetch and show in screen the data is showing in print but while showing in screen its giving error of NoSuchMethodErrorClass 'ResponsiveObjectSettingByUser' has no instance method 'car' receiver: Instance,
GET FUNCTION
Future<ResponseObjectSettingByUser> _list;
final String _url = '<LINK>';
Future<ResponseObjectSettingByUser> getUserSettings() async {
ResponseObjectSettingByUser responseData = null;
var response = await http
.get(_url + '<link>', headers: {
"Authorization":
'Bearer <TOKEN>',
});
var responseJson = json.decode(response.body);
if (response.statusCode == 200) {
responseJson = settingByUserModel(response.body);
print(responseJson.toJson().toString());
}
return responseJson;
}
Initilize
#override
void initState() {
super.initState();
_list = getUserSettings();
}
MODEL CLASS (ResponseObjectSettingByUser)
// To parse this JSON data, do
//
// final welcome = welcomeFromJson(jsonString);
import 'dart:convert';
ResponseObjectSettingByUser settingByUserModel(String str) => ResponseObjectSettingByUser.fromJson(json.decode(str));
String welcomeToJson(ResponseObjectSettingByUser data) => json.encode(data.toJson());
class ResponseObjectSettingByUser {
ResponseObjectSettingByUser({
this.array,
});
Array array;
factory ResponseObjectSettingByUser.fromJson(Map<String, dynamic> json) => ResponseObjectSettingByUser(
array: Array.fromJson(json["array"]),
);
Map<String, dynamic> toJson() => {
"array": array.toJson(),
};
}
class Array {
Array({
this.car,
});
List<Car> car;
factory Array.fromJson(Map<String, dynamic> json) => Array(
car: List<Car>.from(json["car"].map((x) => Car.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"car": List<dynamic>.from(car.map((x) => x.toJson())),
};
}
class Car {
Car({
this.id,
this.name,
this.numberKmsMin,
this.numberKmsMax,
this.priceMin,
this.priceMax,
this.powerHorseMin,
this.powerHorseMax,
this.status,
this.isSaved,
this.markId,
this.markName,
this.markImageUrl,
this.modelId,
this.modelName,
this.modelImageUrl,
this.bodyworkId,
this.bodyworkName,
this.fuelId,
this.fuelName,
this.motorizationId,
this.motorizationName,
this.rimsId,
this.rimsName,
this.serieId,
this.serieName,
this.interiorEquipmentId,
this.interiorEquipmentName,
this.upholsteryId,
this.upholsteryName,
this.upholsteryLeatherFabricName,
this.iluminationId,
this.iluminationName,
this.externalEquipmentId,
this.externalEquipmentName,
this.dateStartMin,
this.dateEndMax,
this.settings,
});
int id;
String name;
String numberKmsMin;
String numberKmsMax;
String priceMin;
String priceMax;
String powerHorseMin;
String powerHorseMax;
String status;
int isSaved;
int markId;
String markName;
String markImageUrl;
int modelId;
String modelName;
String modelImageUrl;
int bodyworkId;
String bodyworkName;
int fuelId;
String fuelName;
int motorizationId;
String motorizationName;
dynamic rimsId;
dynamic rimsName;
int serieId;
String serieName;
int interiorEquipmentId;
String interiorEquipmentName;
int upholsteryId;
String upholsteryName;
String upholsteryLeatherFabricName;
int iluminationId;
String iluminationName;
int externalEquipmentId;
String externalEquipmentName;
String dateStartMin;
String dateEndMax;
List<Setting> settings;
factory Car.fromJson(Map<String, dynamic> json) => Car(
id: json["id"],
name: json["name"],
numberKmsMin: json["number_kms_min"],
numberKmsMax: json["number_kms_max"],
priceMin: json["price_min"],
priceMax: json["price_max"],
powerHorseMin: json["power_horse_min"],
powerHorseMax: json["power_horse_max"],
status: json["status"],
isSaved: json["is_saved"],
markId: json["mark_id"],
markName: json["mark_name"],
markImageUrl: json["mark_image_url"],
modelId: json["model_id"],
modelName: json["model_name"],
modelImageUrl: json["model_image_url"],
bodyworkId: json["bodywork_id"],
bodyworkName: json["bodywork_name"],
fuelId: json["fuel_id"],
fuelName: json["fuel_name"],
motorizationId: json["Motorization_id"],
motorizationName: json["Motorization_name"],
rimsId: json["rims_id"],
rimsName: json["rims_name"],
serieId: json["serie_id"],
serieName: json["serie_name"],
interiorEquipmentId: json["Interior_equipment_id"],
interiorEquipmentName: json["Interior_equipment_name"],
upholsteryId: json["Upholstery_id"],
upholsteryName: json["Upholstery_name"],
upholsteryLeatherFabricName: json["Upholstery_Leather_fabric_name"],
iluminationId: json["ilumination_id"],
iluminationName: json["ilumination_name"],
externalEquipmentId: json["external_equipment_id"],
externalEquipmentName: json["external_equipment_name"],
dateStartMin: json["date_start_min"],
dateEndMax: json["date_end_max"],
settings: json["settings"] == null ? null : List<Setting>.from(json["settings"].map((x) => Setting.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"number_kms_min": numberKmsMin,
"number_kms_max": numberKmsMax,
"price_min": priceMin,
"price_max": priceMax,
"power_horse_min": powerHorseMin,
"power_horse_max": powerHorseMax,
"status": status,
"is_saved": isSaved,
"mark_id": markId,
"mark_name": markName,
"mark_image_url": markImageUrl,
"model_id": modelId,
"model_name": modelName,
"model_image_url": modelImageUrl,
"bodywork_id": bodyworkId,
"bodywork_name": bodyworkName,
"fuel_id": fuelId,
"fuel_name": fuelName,
"Motorization_id": motorizationId,
"Motorization_name": motorizationName,
"rims_id": rimsId,
"rims_name": rimsName,
"serie_id": serieId,
"serie_name": serieName,
"Interior_equipment_id": interiorEquipmentId,
"Interior_equipment_name": interiorEquipmentName,
"Upholstery_id": upholsteryId,
"Upholstery_name": upholsteryName,
"Upholstery_Leather_fabric_name": upholsteryLeatherFabricName,
"ilumination_id": iluminationId,
"ilumination_name": iluminationName,
"external_equipment_id": externalEquipmentId,
"external_equipment_name": externalEquipmentName,
"date_start_min": dateStartMin,
"date_end_max": dateEndMax,
"settings": settings == null ? null : List<dynamic>.from(settings.map((x) => x.toJson())),
};
}
class Setting {
Setting({
this.id,
this.name,
});
int id;
String name;
factory Setting.fromJson(Map<String, dynamic> json) => Setting(
id: json["id"],
name: json["name"],
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
};
}
To show data on screen using
child: FutureBuilder(
future: getUserSettings(),
builder: (BuildContext context,
AsyncSnapshot snapshot) {
final countries = snapshot.data;
if (snapshot.data == null) {
//IF NULL
return Container(
child: Center(
child: Text("Loading..."),
),
);
} else {
return Stack(
children: [
Container(
child: Text(snapshot.data.Car[0].id)
),
),
],
);
}
},
),
JSON Data is like this.
{
"array": {
"car": [
{
"id": 131,
"name": "120",
"number_kms_min": "1000",
"number_kms_max": "10000",
"price_min": "10000",
"price_max": "1000",
"power_horse_min": "100",
"power_horse_max": "120",
"status": "1",
"is_saved": 0,
"mark_id": 1,
"mark_name": "BMW",
"mark_image_url": "https://cdn0.iconfinder.com/data/icons/car-brands/550/BMW_logo-512.png",
"model_id": 1,
"model_name": "Serie 1",
"model_image_url": "https://www.bmw.pt/content/dam/bmw/common/all-models/1-series/5-door/2019/navigation/bmw-1-series-modelfinder.png",
"bodywork_id": 1,
"bodywork_name": "Coupé",
"fuel_id": 1,
"fuel_name": "Gasolina",
"Motorization_id": 1,
"Motorization_name": "Manual",
"rims_id": 1,
"rims_name": "Preto fosco\r\n5 raios",
"serie_id": 1,
"serie_name": "120",
"Interior_equipment_id": 1,
"Interior_equipment_name": "Bancos desportivos\r\n",
"Upholstery_id": 1,
"Upholstery_name": "Preto",
"Upholstery_Leather_fabric_name": "Preto",
"ilumination_id": 1,
"ilumination_name": "Iluminação ambiente",
"external_equipment_id": 1,
"external_equipment_name": "Para-choques desportivos",
"date_start_min": "03/18",
"date_end_max": "09/19"
},
{
"id": 121,
"name": "120",
"number_kms_min": "1000",
"number_kms_max": "10000",
"price_min": "10000",
"price_max": "1000",
"power_horse_min": "100",
"power_horse_max": "120",
"status": "1",
"is_saved": 0,
"mark_id": 1,
"mark_name": "BMW",
"mark_image_url": "https://cdn0.iconfinder.com/data/icons/car-brands/550/BMW_logo-512.png",
"model_id": 1,
"model_name": "Serie 1",
"model_image_url": "https://www.bmw.pt/content/dam/bmw/common/all-models/1-series/5-door/2019/navigation/bmw-1-series-modelfinder.png",
"bodywork_id": 1,
"bodywork_name": "Coupé",
"fuel_id": 1,
"fuel_name": "Gasolina",
"Motorization_id": 1,
"Motorization_name": "Manual",
"rims_id": 1,
"rims_name": "Preto fosco\r\n5 raios",
"serie_id": 1,
"serie_name": "120",
"Interior_equipment_id": 1,
"Interior_equipment_name": "Bancos desportivos\r\n",
"Upholstery_id": 1,
"Upholstery_name": "Preto",
"Upholstery_Leather_fabric_name": "Preto",
"ilumination_id": 1,
"ilumination_name": "Iluminação ambiente",
"external_equipment_id": 1,
"external_equipment_name": "Para-choques desportivos",
"date_start_min": "03/18",
"date_end_max": "09/19"
},
{
"id": 111,
"name": "120",
"number_kms_min": "1000",
"number_kms_max": "10000",
"price_min": "10000",
"price_max": "1000",
"power_horse_min": "100",
"power_horse_max": "120",
"status": "1",
"is_saved": 0,
"mark_id": 1,
"mark_name": "BMW",
"mark_image_url": "https://cdn0.iconfinder.com/data/icons/car-brands/550/BMW_logo-512.png",
"model_id": 1,
"model_name": "Serie 1",
"model_image_url": "https://www.bmw.pt/content/dam/bmw/common/all-models/1-series/5-door/2019/navigation/bmw-1-series-modelfinder.png",
"bodywork_id": 1,
"bodywork_name": "Coupé",
"fuel_id": 1,
"fuel_name": "Gasolina",
"Motorization_id": 1,
"Motorization_name": "Manual",
"rims_id": 1,
"rims_name": "Preto fosco\r\n5 raios",
"serie_id": 1,
"serie_name": "120",
"Interior_equipment_id": 1,
"Interior_equipment_name": "Bancos desportivos\r\n",
"Upholstery_id": 1,
"Upholstery_name": "Preto",
"Upholstery_Leather_fabric_name": "Preto",
"ilumination_id": 1,
"ilumination_name": "Iluminação ambiente",
"external_equipment_id": 1,
"external_equipment_name": "Para-choques desportivos",
"date_start_min": "03/18",
"date_end_max": "09/19"
}
]
}
}
You can copy paste run full code below
You can use AsyncSnapshot<ResponseObjectSettingByUser> and check connectionState and use snapshot.data.array.car.length in ListView
code snippet
FutureBuilder(
future: _list,
builder:
(context, AsyncSnapshot<ResponseObjectSettingByUser> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
return Text('none');
case ConnectionState.waiting:
return Center(child: CircularProgressIndicator());
case ConnectionState.active:
return Text('');
case ConnectionState.done:
if (snapshot.hasError) {
return Text(
'${snapshot.error}',
style: TextStyle(color: Colors.red),
);
} else {
return ListView.builder(
itemCount: snapshot.data.array.car.length,
itemBuilder: (context, index) {
working demo
full code
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
ResponseObjectSettingByUser settingByUserModel(String str) =>
ResponseObjectSettingByUser.fromJson(json.decode(str));
String welcomeToJson(ResponseObjectSettingByUser data) =>
json.encode(data.toJson());
class ResponseObjectSettingByUser {
ResponseObjectSettingByUser({
this.array,
});
Array array;
factory ResponseObjectSettingByUser.fromJson(Map<String, dynamic> json) =>
ResponseObjectSettingByUser(
array: Array.fromJson(json["array"]),
);
Map<String, dynamic> toJson() => {
"array": array.toJson(),
};
}
class Array {
Array({
this.car,
});
List<Car> car;
factory Array.fromJson(Map<String, dynamic> json) => Array(
car: List<Car>.from(json["car"].map((x) => Car.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"car": List<dynamic>.from(car.map((x) => x.toJson())),
};
}
class Car {
Car({
this.id,
this.name,
this.numberKmsMin,
this.numberKmsMax,
this.priceMin,
this.priceMax,
this.powerHorseMin,
this.powerHorseMax,
this.status,
this.isSaved,
this.markId,
this.markName,
this.markImageUrl,
this.modelId,
this.modelName,
this.modelImageUrl,
this.bodyworkId,
this.bodyworkName,
this.fuelId,
this.fuelName,
this.motorizationId,
this.motorizationName,
this.rimsId,
this.rimsName,
this.serieId,
this.serieName,
this.interiorEquipmentId,
this.interiorEquipmentName,
this.upholsteryId,
this.upholsteryName,
this.upholsteryLeatherFabricName,
this.iluminationId,
this.iluminationName,
this.externalEquipmentId,
this.externalEquipmentName,
this.dateStartMin,
this.dateEndMax,
this.settings,
});
int id;
String name;
String numberKmsMin;
String numberKmsMax;
String priceMin;
String priceMax;
String powerHorseMin;
String powerHorseMax;
String status;
int isSaved;
int markId;
String markName;
String markImageUrl;
int modelId;
String modelName;
String modelImageUrl;
int bodyworkId;
String bodyworkName;
int fuelId;
String fuelName;
int motorizationId;
String motorizationName;
dynamic rimsId;
dynamic rimsName;
int serieId;
String serieName;
int interiorEquipmentId;
String interiorEquipmentName;
int upholsteryId;
String upholsteryName;
String upholsteryLeatherFabricName;
int iluminationId;
String iluminationName;
int externalEquipmentId;
String externalEquipmentName;
String dateStartMin;
String dateEndMax;
List<Setting> settings;
factory Car.fromJson(Map<String, dynamic> json) => Car(
id: json["id"],
name: json["name"],
numberKmsMin: json["number_kms_min"],
numberKmsMax: json["number_kms_max"],
priceMin: json["price_min"],
priceMax: json["price_max"],
powerHorseMin: json["power_horse_min"],
powerHorseMax: json["power_horse_max"],
status: json["status"],
isSaved: json["is_saved"],
markId: json["mark_id"],
markName: json["mark_name"],
markImageUrl: json["mark_image_url"],
modelId: json["model_id"],
modelName: json["model_name"],
modelImageUrl: json["model_image_url"],
bodyworkId: json["bodywork_id"],
bodyworkName: json["bodywork_name"],
fuelId: json["fuel_id"],
fuelName: json["fuel_name"],
motorizationId: json["Motorization_id"],
motorizationName: json["Motorization_name"],
rimsId: json["rims_id"],
rimsName: json["rims_name"],
serieId: json["serie_id"],
serieName: json["serie_name"],
interiorEquipmentId: json["Interior_equipment_id"],
interiorEquipmentName: json["Interior_equipment_name"],
upholsteryId: json["Upholstery_id"],
upholsteryName: json["Upholstery_name"],
upholsteryLeatherFabricName: json["Upholstery_Leather_fabric_name"],
iluminationId: json["ilumination_id"],
iluminationName: json["ilumination_name"],
externalEquipmentId: json["external_equipment_id"],
externalEquipmentName: json["external_equipment_name"],
dateStartMin: json["date_start_min"],
dateEndMax: json["date_end_max"],
settings: json["settings"] == null
? null
: List<Setting>.from(
json["settings"].map((x) => Setting.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"number_kms_min": numberKmsMin,
"number_kms_max": numberKmsMax,
"price_min": priceMin,
"price_max": priceMax,
"power_horse_min": powerHorseMin,
"power_horse_max": powerHorseMax,
"status": status,
"is_saved": isSaved,
"mark_id": markId,
"mark_name": markName,
"mark_image_url": markImageUrl,
"model_id": modelId,
"model_name": modelName,
"model_image_url": modelImageUrl,
"bodywork_id": bodyworkId,
"bodywork_name": bodyworkName,
"fuel_id": fuelId,
"fuel_name": fuelName,
"Motorization_id": motorizationId,
"Motorization_name": motorizationName,
"rims_id": rimsId,
"rims_name": rimsName,
"serie_id": serieId,
"serie_name": serieName,
"Interior_equipment_id": interiorEquipmentId,
"Interior_equipment_name": interiorEquipmentName,
"Upholstery_id": upholsteryId,
"Upholstery_name": upholsteryName,
"Upholstery_Leather_fabric_name": upholsteryLeatherFabricName,
"ilumination_id": iluminationId,
"ilumination_name": iluminationName,
"external_equipment_id": externalEquipmentId,
"external_equipment_name": externalEquipmentName,
"date_start_min": dateStartMin,
"date_end_max": dateEndMax,
"settings": settings == null
? null
: List<dynamic>.from(settings.map((x) => x.toJson())),
};
}
class Setting {
Setting({
this.id,
this.name,
});
int id;
String name;
factory Setting.fromJson(Map<String, dynamic> json) => Setting(
id: json["id"],
name: json["name"],
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
};
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Future<ResponseObjectSettingByUser> _list;
Future<ResponseObjectSettingByUser> getUserSettings() async {
ResponseObjectSettingByUser responseData = null;
/*var response = await http
.get(_url + '<link>', headers: {
"Authorization":
'Bearer <TOKEN>',
});*/
String jsonString = '''
{
"array": {
"car": [
{
"id": 131,
"name": "120",
"number_kms_min": "1000",
"number_kms_max": "10000",
"price_min": "10000",
"price_max": "1000",
"power_horse_min": "100",
"power_horse_max": "120",
"status": "1",
"is_saved": 0,
"mark_id": 1,
"mark_name": "BMW",
"mark_image_url": "https://cdn0.iconfinder.com/data/icons/car-brands/550/BMW_logo-512.png",
"model_id": 1,
"model_name": "Serie 1",
"model_image_url": "https://www.bmw.pt/content/dam/bmw/common/all-models/1-series/5-door/2019/navigation/bmw-1-series-modelfinder.png",
"bodywork_id": 1,
"bodywork_name": "Coupé",
"fuel_id": 1,
"fuel_name": "Gasolina",
"Motorization_id": 1,
"Motorization_name": "Manual",
"rims_id": 1,
"rims_name": "Preto fosco\r\n5 raios",
"serie_id": 1,
"serie_name": "120",
"Interior_equipment_id": 1,
"Interior_equipment_name": "Bancos desportivos\r\n",
"Upholstery_id": 1,
"Upholstery_name": "Preto",
"Upholstery_Leather_fabric_name": "Preto",
"ilumination_id": 1,
"ilumination_name": "Iluminação ambiente",
"external_equipment_id": 1,
"external_equipment_name": "Para-choques desportivos",
"date_start_min": "03/18",
"date_end_max": "09/19"
},
{
"id": 121,
"name": "120",
"number_kms_min": "1000",
"number_kms_max": "10000",
"price_min": "10000",
"price_max": "1000",
"power_horse_min": "100",
"power_horse_max": "120",
"status": "1",
"is_saved": 0,
"mark_id": 1,
"mark_name": "BMW",
"mark_image_url": "https://cdn0.iconfinder.com/data/icons/car-brands/550/BMW_logo-512.png",
"model_id": 1,
"model_name": "Serie 1",
"model_image_url": "https://www.bmw.pt/content/dam/bmw/common/all-models/1-series/5-door/2019/navigation/bmw-1-series-modelfinder.png",
"bodywork_id": 1,
"bodywork_name": "Coupé",
"fuel_id": 1,
"fuel_name": "Gasolina",
"Motorization_id": 1,
"Motorization_name": "Manual",
"rims_id": 1,
"rims_name": "Preto fosco\r\n5 raios",
"serie_id": 1,
"serie_name": "120",
"Interior_equipment_id": 1,
"Interior_equipment_name": "Bancos desportivos\r\n",
"Upholstery_id": 1,
"Upholstery_name": "Preto",
"Upholstery_Leather_fabric_name": "Preto",
"ilumination_id": 1,
"ilumination_name": "Iluminação ambiente",
"external_equipment_id": 1,
"external_equipment_name": "Para-choques desportivos",
"date_start_min": "03/18",
"date_end_max": "09/19"
},
{
"id": 111,
"name": "120",
"number_kms_min": "1000",
"number_kms_max": "10000",
"price_min": "10000",
"price_max": "1000",
"power_horse_min": "100",
"power_horse_max": "120",
"status": "1",
"is_saved": 0,
"mark_id": 1,
"mark_name": "BMW",
"mark_image_url": "https://cdn0.iconfinder.com/data/icons/car-brands/550/BMW_logo-512.png",
"model_id": 1,
"model_name": "Serie 1",
"model_image_url": "https://www.bmw.pt/content/dam/bmw/common/all-models/1-series/5-door/2019/navigation/bmw-1-series-modelfinder.png",
"bodywork_id": 1,
"bodywork_name": "Coupé",
"fuel_id": 1,
"fuel_name": "Gasolina",
"Motorization_id": 1,
"Motorization_name": "Manual",
"rims_id": 1,
"rims_name": "Preto fosco\r\n5 raios",
"serie_id": 1,
"serie_name": "120",
"Interior_equipment_id": 1,
"Interior_equipment_name": "Bancos desportivos\r\n",
"Upholstery_id": 1,
"Upholstery_name": "Preto",
"Upholstery_Leather_fabric_name": "Preto",
"ilumination_id": 1,
"ilumination_name": "Iluminação ambiente",
"external_equipment_id": 1,
"external_equipment_name": "Para-choques desportivos",
"date_start_min": "03/18",
"date_end_max": "09/19"
}
]
}
}
''';
http.Response response = http.Response(jsonString, 200);
if (response.statusCode == 200) {
String postProcessing =
response.body.replaceAll('\n', "").replaceAll('\r', "");
var responseJson = settingByUserModel(postProcessing);
print(responseJson.toJson().toString());
return responseJson;
}
}
#override
void initState() {
_list = getUserSettings();
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: FutureBuilder(
future: _list,
builder:
(context, AsyncSnapshot<ResponseObjectSettingByUser> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
return Text('none');
case ConnectionState.waiting:
return Center(child: CircularProgressIndicator());
case ConnectionState.active:
return Text('');
case ConnectionState.done:
if (snapshot.hasError) {
return Text(
'${snapshot.error}',
style: TextStyle(color: Colors.red),
);
} else {
return ListView.builder(
itemCount: snapshot.data.array.car.length,
itemBuilder: (context, index) {
return Card(
elevation: 6.0,
child: Padding(
padding: const EdgeInsets.only(
top: 6.0,
bottom: 6.0,
left: 8.0,
right: 8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(snapshot
.data.array.car[index].markName),
Spacer(),
Text(snapshot
.data.array.car[index].id.toString()),
],
),
));
});
}
}
}));
}
}