How to display nested json flutter - json

what should I do to display this data
"result": [
{
"department_id": null,
"crime_time_id": "5562f55f-54aa-4e94-9f6c-9ce25d9e3fd9",
"village_id": "3174031001",
"cases": 3,
"villages": 3,
"target_id": null,
"department": null,
"crime_time": {
"id": "5562f55f-54aa-4e94-9f6c-9ce25d9e3fd9",
"name": "00.00 - 02.00"
},
"village": {
"id": "3174031001",
"name": "MAMPANG PRAPATAN"
}
},
{
"department_id": null,
"crime_time_id": "ca56d7a3-fdea-446a-a628-cc7091f314de",
"village_id": "1604082010",
"cases": 1,
"villages": 1,
"target_id": null,
"department": null,
"crime_time": {
"id": "ca56d7a3-fdea-446a-a628-cc7091f314de",
"name": "06.00 - 08.00"
},
"village": {
"id": "1604082010",
"name": "TANJUNG SIRIH"
}
}
]
I have try to handle this but there is some display error
'expected a value of type 'int?' but got one of type 'String' and
'the method fromjson isnt defined for the type data. try correcting the name to the name of an exsiting method
this my model:
class rangkumanKasus {
int? department_id;
String? crime_time_id;
int? village_id;
int? cases;
int? villages;
int? target_id;
String? department;
final Crime_Time crime_time;
final Village village;
rangkumanKasus({
this.department_id,
this.crime_time_id,
this.village_id,
this.cases,
this.villages,
this.target_id,
this.department,
required this.crime_time,
required this.village,
});
factory rangkumanKasus.fromJson(Map<String, dynamic> json) {
return rangkumanKasus(
department_id: json["department_id"],
crime_time_id: json['crime_time_id'],
village_id: json['village_id'],
cases: json['cases'],
villages: json['villages'],
target_id: json['target_id'],
department: json['department'],
crime_time: Crime_Time.fromJson(json['crime_time']),
village: Village.fromJson(json['village']),
);
}
}
class Crime_Time {
int? id;
String? name;
Crime_Time({
this.id,
this.name,
});
factory Crime_Time.fromJson(Map<dynamic, dynamic> json) {
return Crime_Time(
id: json['id'],
name: json['name'],
);
}
}
class Village {
int? id;
String? name;
Village({
this.id,
this.name,
});
factory Village.fromJson(Map<dynamic, dynamic> json) {
return Village(
id: json['id'],
name: json['name'],
);
}
}
and this how I try to display
Container(
child: FutureBuilder<List<rangkumanKasus>>(
future: listData,
builder: (context, snapshot) {
if (snapshot.hasData) {
List<rangkumanKasus> isiData = snapshot.data!;
return ListView.builder(
shrinkWrap: true,
itemCount: isiData.length,
itemBuilder: (context, index) {
return Container(
child: Text(
isiData[index].crime_time.name!,
style: TextStyle(color: Colors.red),
));
});
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return const CircularProgressIndicator();
}),

Related

type 'String' is not a subtype of type 'int' of 'index' while getting media fields using the instagram API

i'm trying to get media fields from the instagram api and i'm getting this error
type 'String' is not a subtype of type 'int' of 'index'
here's Homepage.dart :
import 'package:flutter/material.dart';
import 'package:get_storage/get_storage.dart';
import 'package:insta_details/models/data.dart';
import 'package:insta_details/utils/custom_dio_mixin.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
static String id = "HomePage";
#override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with CustomDioMixin {
bool loading = true;
bool error = false;
late Media media;
#override
void initState() {
super.initState();
getData();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: loading
? const Center(
child: CircularProgressIndicator(),
)
: error
? const Center(
child: Text('An error has occurred!'),
)
: ListView.builder(
itemBuilder: (context, index) => MediaWidget(
media: media,
),
),
),
);
}
Future<void> getData() async {
try {
final storage = GetStorage();
final token = storage.read("accessToken");
Media? media;
final response = await dio.get(
'https://graph.instagram.com/me/media?fields=id,caption,media_url,timestamp&access_token=$token',
);
print("get data response => ${response.statusCode} ${response.data}");
Media mediadata = Media.fromJson(response.data);
print(mediadata);
} catch (e) {
print("get data failed");
print(e);
setState(() {
error = true;
});
} finally {
setState(() {
loading = false;
});
}
}
}
class MediaWidget extends StatelessWidget {
final Media media;
const MediaWidget({Key? key, required this.media}) : super(key: key);
#override
Widget build(BuildContext context) {
return GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
itemCount: 6,
itemBuilder: (context, index) {
return Image.network(media.mediaUrl);
},
);
}
}
and here data.dart :
class Media {
Media({
required this.id,
required this.caption,
required this.mediaUrl,
required this.timestamp,
});
String id;
String caption;
String mediaUrl;
String timestamp;
factory Media.fromJson(Map<String, dynamic> json) => Media(
id: json["data"]["id"] as String,
caption: json["data"]["caption"] as String,
mediaUrl: json["data"]["media_url"] as String,
timestamp: json["data"]["timestamp"] as String,
);
Map<String, dynamic> toJson() => {
"id": id,
"caption": caption,
"media_url": mediaUrl,
"timestamp": timestamp,
};
}
and the log :
I/flutter ( 5699): get data response => 200 {data: [{id: 18106429915287733, caption: cabin in the woods, media_url: https://scontent.cdninstagram.com/v/t51.29350-15/272751472_358111429123560_6575694365508668882_n.jpg?_nc_cat=100&ccb=1-5&_nc_sid=8ae9d6&_nc_ohc=0omRv4cUGtwAX8bbmC7&_nc_ht=scontent.cdninstagram.com&edm=ANo9K5cEAAAA&oh=00_AT_fqBkL5ykJXWRj7Rcy4nCnyuXEKh-8o0TX9FJkJ4dcfQ&oe=61FD881A, timestamp: 2022-01-27T11:15:07+0000}, {id: 17917394609104775, caption: Truck, media_url: https://scontent.cdninstagram.com/v/t51.29350-15/272701475_1080001635904581_1705933746471766077_n.jpg?_nc_cat=107&ccb=1-5&_nc_sid=8ae9d6&_nc_ohc=ZfSpeg7rHn4AX89PW0c&_nc_ht=scontent.cdninstagram.com&edm=ANo9K5cEAAAA&oh=00_AT_Qbj7zOH-UEzplA9mdIrCHaeb9EBBuz1RjKJclN9Q2RA&oe=61FE9898, timestamp: 2022-01-27T11:14:26+0000}, {id: 17921627228176014, caption: Gaara, media_url: https://scontent.cdninstagram.com/v/t51.29350-15/272660463_892749041374464_5507853711157520506_n.jpg?_nc_cat=101&ccb=1-5&_nc_sid=8ae9d6&_nc_ohc=va5seINOs-4AX9vOy4L&_nc_ht=scontent.cdninst
I/flutter ( 5699): get data failed
I/flutter ( 5699): type 'String' is not a subtype of type 'int' of 'index'
my JSON response :
{
"data": [
{
"id": "18106429915287733",
"caption": "cabin in the woods",
"media_type": "IMAGE",
"media_url": "https://scontent-iad3-1.cdninstagram.com/v/t51.29350-15/272751472_358111429123560_6575694365508668882_n.jpg?_nc_cat=100&ccb=1-5&_nc_sid=8ae9d6&_nc_ohc=xXGDvxMsycAAX_U_-55&_nc_ht=scontent-iad3-1.cdninstagram.com&edm=ANo9K5cEAAAA&oh=00_AT-EuNnLxrBSNirBOl1prRXlHepdhQqUjYRBEv3Zh_Ld6Q&oe=61FD881A",
"username": "parekchampl",
"timestamp": "2022-01-27T11:15:07+0000"
},
{
"id": "17917394609104775",
"caption": "Truck",
"media_type": "IMAGE",
"media_url": "https://scontent-iad3-1.cdninstagram.com/v/t51.29350-15/272701475_1080001635904581_1705933746471766077_n.jpg?_nc_cat=107&ccb=1-5&_nc_sid=8ae9d6&_nc_ohc=ZfSpeg7rHn4AX_J_eQs&_nc_ht=scontent-iad3-1.cdninstagram.com&edm=ANo9K5cEAAAA&oh=00_AT92hbhb0XK56kxC-_e8kpM6QFLazDH0TDCfdIdEIpNinw&oe=61FC9E58",
"username": "parekchampl",
"timestamp": "2022-01-27T11:14:26+0000"
},
{
"id": "17921627228176014",
"caption": "Gaara",
"media_type": "IMAGE",
"media_url": "https://scontent-iad3-1.cdninstagram.com/v/t51.29350-15/272660463_892749041374464_5507853711157520506_n.jpg?_nc_cat=101&ccb=1-5&_nc_sid=8ae9d6&_nc_ohc=va5seINOs-4AX_SB6jL&_nc_ht=scontent-iad3-1.cdninstagram.com&edm=ANo9K5cEAAAA&oh=00_AT8rviJ6wbaT0yF1Hq2VprtnQ-W0rARS5oxIr52MIhC0Rw&oe=61FD720B",
"username": "parekchampl",
"timestamp": "2022-01-27T11:13:42+0000"
},
{
"id": "18024346318348836",
"caption": "Marceline",
"media_type": "IMAGE",
"media_url": "https://scontent-iad3-1.cdninstagram.com/v/t51.29350-15/272807293_686124672409566_4991399943515126026_n.jpg?_nc_cat=106&ccb=1-5&_nc_sid=8ae9d6&_nc_ohc=JMfTMSD_1c8AX-m5WDx&_nc_ht=scontent-iad3-1.cdninstagram.com&edm=ANo9K5cEAAAA&oh=00_AT_P38eDVtcqEYL053wGPkLjhHStLCh7_fgFnCg4LcH1yA&oe=61FD1F82",
"username": "parekchampl",
"timestamp": "2022-01-27T11:13:02+0000"
},
{
"id": "17859174368680579",
"caption": "uchiha shisui",
"media_type": "IMAGE",
"media_url": "https://scontent-iad3-1.cdninstagram.com/v/t51.29350-15/272721151_749467822692662_5191995429373550055_n.jpg?_nc_cat=111&ccb=1-5&_nc_sid=8ae9d6&_nc_ohc=01A68vtgY-kAX-ux6iB&_nc_ht=scontent-iad3-1.cdninstagram.com&edm=ANo9K5cEAAAA&oh=00_AT9oWtK9VWV8j3c8Ij2YXctIpuh9sC-NJO1BLCwFObDDSA&oe=61FE0B03",
"username": "parekchampl",
"timestamp": "2022-01-27T11:12:35+0000"
},
{
"id": "17917757036265369",
"caption": "Son and Father",
"media_type": "IMAGE",
"media_url": "https://scontent-iad3-1.cdninstagram.com/v/t51.29350-15/272660947_1107548556714461_1575953024252145708_n.jpg?_nc_cat=100&ccb=1-5&_nc_sid=8ae9d6&_nc_ohc=Mzj5Wp9sv_oAX_2Z4Nv&_nc_ht=scontent-iad3-1.cdninstagram.com&edm=ANo9K5cEAAAA&oh=00_AT8Ywp3DUIemrIoCPajFvivfTG_-AWvEs2fpkngYXUN6Lg&oe=61FE17A1",
"username": "parekchampl",
"timestamp": "2022-01-27T11:11:47+0000"
}
],
"paging": {
"cursors": {
"before": "QVFIUnpEcERJTXdYRjd3SVp3MUo2U25UeWhhdlgxQ2xMY0diR2pYVFhCVl9TUUhlM1hqYllKWUpEWXJtYW5RWW41am1Lc3B4U281TU14ZAFoxSVBkMVRsZAkZAB",
"after": "QVFIUkgtUzExdDNsYzgwUFhGdnRXQlB6N0JkZATVFeU1DVkhzXzduLTF1RklpR1A5MDNMeWVEemtzdE15OVBlYmpYb29mQlVtdDJsX1N2SUcwa2ZAkc21jblZAn"
}
}
}
According to the documentation : https://developers.facebook.com/docs/instagram-basic-display-api/reference/media ,every field is a String
factory Media.fromJson(Map<String, dynamic> json) => Media(
id: json["data"]["id"] as String,
caption: json["data"]["caption"] as String,
mediaUrl: json["data"]["media_url"] as String,
timestamp: json["data"]["timestamp"] as String,
);
Or change to something like below:
factory Media.fromJson(Map<String, dynamic> json) => Media(
id: int.parse(json["data"]["id"] as String),
caption: json["data"]["caption"] as String,
mediaUrl: json["data"]["media_url"] as String,
timestamp: DateTime.parse(json["data"]["timestamp"] as String),
);
The value of your data key is a List not a Map. Here's an example:
const responseData =
{
"data":[
{
"id":"18106429915287733",
"caption":"cabin in the woods",
"media_type":"IMAGE",
"media_url":"https://scontent-iad3-1.cdninstagram.com/v/t51.29350-15/272751472_358111429123560_6575694365508668882_n.jpg?_nc_cat=100&ccb=1-5&_nc_sid=8ae9d6&_nc_ohc=xXGDvxMsycAAX_U_-55&_nc_ht=scontent-iad3-1.cdninstagram.com&edm=ANo9K5cEAAAA&oh=00_AT-EuNnLxrBSNirBOl1prRXlHepdhQqUjYRBEv3Zh_Ld6Q&oe=61FD881A",
"username":"parekchampl",
"timestamp":"2022-01-27T11:15:07+0000"
},
{
"id":"17917394609104775",
"caption":"Truck",
"media_type":"IMAGE",
"media_url":"https://scontent-iad3-1.cdninstagram.com/v/t51.29350-15/272701475_1080001635904581_1705933746471766077_n.jpg?_nc_cat=107&ccb=1-5&_nc_sid=8ae9d6&_nc_ohc=ZfSpeg7rHn4AX_J_eQs&_nc_ht=scontent-iad3-1.cdninstagram.com&edm=ANo9K5cEAAAA&oh=00_AT92hbhb0XK56kxC-_e8kpM6QFLazDH0TDCfdIdEIpNinw&oe=61FC9E58",
"username":"parekchampl",
"timestamp":"2022-01-27T11:14:26+0000"
}
]
};
void main() {
final mediaList = responseData["data"]!.map((entry) => Media.fromJson(entry))
.toList();
for (var media in mediaList) {
print(media.id);
}
}
class Media {
Media({
required this.id,
required this.caption,
required this.mediaUrl,
required this.timestamp,
});
int? id;
String caption;
String mediaUrl;
String timestamp;
factory Media.fromJson(Map<String, dynamic> json) {
return Media(
id: int.tryParse(json["id"]),
caption: json["caption"],
mediaUrl: json["media_url"],
timestamp: json["timestamp"],
);
}
Map<String, dynamic> toJson() => {
"id": id.toString(),
"caption": caption,
"media_url": mediaUrl,
"timestamp": timestamp,
};
}
On your model class id is nullable int, but you are receiving id as String.
You can typecast string to int On your Media.fromJson, while the id accept null value, if something wrong happen id will get null value.
factory Media.fromJson(Map<String, dynamic> json) => Media(
id: int.tryParse(json["data"]["id"]),
And for toJson pass id as String
Map<String, dynamic> toJson() => {
"id": id.toString(),
More about int.tryParse.

flutter: how to parse super complex json file?

i have a super long json file to be parsed but once i fetch it in a FutureBuilder it keeps erroring that i used a null check operator on a null value, to me seems like i don't know the logic..!
here's the simplified json:
{
"city": {
"Name": "oklahoma",
"Month": [
{
"number": "01",
"day": [
{
"number": "01",
"employee": "jesse m."
},
{
"number": "02",
"employee": "john s."
},
{
"number": "03",
"name": "tyler r."
}
]
},
{
"number": "02",
"day": [
{
"number": "01",
"employee": "mat w."
},
{
"number": "02",
"employee": "may j."
},
{
"number": "03",
"name": "eric r."
}
]
}
]
}
}
note that i have one city and the json has the data of every individual days throughout the whole year
and here's the model:
// To parse this JSON data, do
//
// final company = companyFromJson(jsonString);
import 'dart:convert';
company companyFromJson(String str) => company.fromJson(json.decode(str));
String companyToJson(company data) => json.encode(data.toJson());
class company {
company({
required this.city,
});
City city;
factory company.fromJson(Map<String, dynamic> json) => company(
city: City.fromJson(json["city"]),
);
Map<String, dynamic> toJson() => {
"city": city.toJson(),
};
}
class City {
City({
required this.name,
required this.month,
});
String name;
List<Month> month;
factory City.fromJson(Map<String, dynamic> json) => City(
name: json["Name"],
month: List<Month>.from(json["Month"].map((x) => Month.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"Name": name,
"Month": List<dynamic>.from(month.map((x) => x.toJson())),
};
}
class Month {
Month({
required this.number,
required this.day,
});
String number;
List<Day> day;
factory Month.fromJson(Map<String, dynamic> json) => Month(
number: json["number"],
day: List<Day>.from(json["day"].map((x) => Day.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"number": number,
"day": List<dynamic>.from(day.map((x) => x.toJson())),
};
}
class Day {
Day({
required this.number,
required this.employee
});
String number;
String employee;
factory Day.fromJson(Map<String, dynamic> json) => Day(
number: json["number"],
employee: json["employee"]
);
Map<String, dynamic> toJson() => {
"number": number,
"employee": employee
};
}
this is the parsing method:
Future<List<Day>> getCompanyEmployee () async {
String jsonString = await DefaultAssetBundle.of(context).loadString('assets/json/OklahomaEmployee.json');
List<dynamic> result = jsonDecode(jsonString);
List<Day> Company = result.map((e) => Day.fromJson(e)).toList();
return Company;
}
this is the implementation:
FutureBuilder<List<Day>>(
future: getCompanyEmployee(),
builder: (context, snapshot) {
var itemList = snapshot.data;
return GridView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
),
itemCount: itemList!.length,
itemBuilder: (BuildContext context, index) {
var itemData = itemList[index];
return ClipRRect(
borderRadius: BorderRadius.circular(25),
child: Container(
height: 10,
color: Colors.white,
width: 10,
child: Center(
child: Column(
children: [
Text(
'employee',
style: TextStyle(fontSize: 15),
),
Text(itemData.employee),
Image.asset(
'assets/Pictures/employees.png',
height: 70,
)
],
),
),
),
);
},
);
},
)
In your FutureBuilder, you just assume the future has already completed. The point of a FutureBuilder is that it has not and you need to deal with that.
You need to account for the fact that your Futurebuilder needs to build something even if the future has not yet completed. The simplest thing to make that happen is to show a CircularProgressIndicator as long as you don't have data.
See What is a Future and how do I use it? for an example of how to do that.

How to display JSON nested ArrayList item in flutter?

I can successfully display PartnerName, PartnerAddress which are in PartnerData[]. Now inside PartnerData there is another ArrayList DayList[] how can I print those arrayList data DayName,TimeFrom etc etc??
{
"Status": "1",
"Message": "",
"Data": {
"EncDietId": "pEl2B9kuumKRxIxLJO76eQ==",
"DietName": "dietcian2",
"Email": null,
"Phone": null,
"AlternatePhone": null,
"Image": "http://myapi/Doctor/65AUCUE8RTD2UKBRV.jpg",
"Description": null,
"Fee": null,
"DiscountedFee": null,
"BookingFee": null,
"VisitDay": null,
"TimeFrom": null,
"TimeTo": null
},
"PartnerData": [
{
"PartnerId": "13",
"EncPartnerId": "65gtodyhbtdInTsJWr1ZkA==",
"PartnerName": "Rasomoy pvt. Hospital",
"PartnerAddress": "Kol,Kol,Kol,Wb",
"Fee": "1200",
"DiscountedFee": "900",
"BookingFee": "500",
"DayList": [
{
"DayName": "Wednesday",
"TimeFrom": "10:00",
"TimeTo": "16:00"
},
{
"DayName": "Friday",
"TimeFrom": "10:00",
"TimeTo": "16:00"
},
{
"DayName": "Saturday",
"TimeFrom": "10:00",
"TimeTo": "16:00"
}
]
}
]
}
My Api
Future<List<PartnerDatum>> dietcianDetailsApi() async {
var jsonResponse;
var response = await http.post(
Uri.parse("http://ggmyapin/api/api/Diet"),
body: ({
'EncId': encDietcianIdRef,
}));
if (response.statusCode == 200) {
print("Correct");
print(response.body);
jsonResponse = json.decode(response.body.toString());
print(jsonResponse);
DietDetailsModel dataModel = dietDetailsModelFromJson(response.body);
print(dataModel.partnerData.length);
for (final item in dataModel.partnerData)
print(item.partnerName);
List<PartnerDatum> arrData =dataModel.partnerData;
return arrData;
} else {
print("Wrong Url");
print(response.body);
throw Exception("Faild to fetch");
}
}
Displying in ListView. For now Successfully can display data PartnerName which are in PartnerData[] . I'm trying to display DayList[] data too. What will be the syntax for this?
Container(
height: blockSizeVertical*30,//38
child: FutureBuilder(
future: dietcianDetailsApi(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
// if (snapshot.connectionState !=ConnectionState.done) {
// return CircularProgressIndicator();
// }
if (snapshot.hasError) {
return Text("Somthing went wrong");
}
if (snapshot.hasData) {
return ListView.builder(
scrollDirection: Axis.horizontal,
physics: BouncingScrollPhysics(),
shrinkWrap: true,
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) =>
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
),
width: blockSizeHorizontal*80,
margin: EdgeInsets.all(10),
child: Stack(children: [
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: blockSizeVertical*0.5),
Text(
'PartnerName : ${snapshot.data[index].partnerName}',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: blockSizeHorizontal*3.5,
fontFamily: 'Poppins',
color: Theme.of(context).primaryColor,
),
textAlign: TextAlign.center,
),
Model Class
// To parse this JSON data, do
//
// final dietDetailsModel = dietDetailsModelFromJson(jsonString);
import 'package:meta/meta.dart';
import 'dart:convert';
DietDetailsModel dietDetailsModelFromJson(String str) => DietDetailsModel.fromJson(json.decode(str));
String dietDetailsModelToJson(DietDetailsModel data) => json.encode(data.toJson());
class DietDetailsModel {
DietDetailsModel({
required this.status,
required this.message,
required this.data,
required this.partnerData,
});
String status;
String message;
Data data;
List<PartnerDatum> partnerData;
factory DietDetailsModel.fromJson(Map<String, dynamic> json) => DietDetailsModel(
status: json["Status"],
message: json["Message"],
data: Data.fromJson(json["Data"]),
partnerData: List<PartnerDatum>.from(json["PartnerData"].map((x) => PartnerDatum.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"Status": status,
"Message": message,
"Data": data.toJson(),
"PartnerData": List<dynamic>.from(partnerData.map((x) => x.toJson())),
};
}
class Data {
Data({
required this.encDietId,
required this.dietName,
required this.email,
required this.phone,
required this.alternatePhone,
required this.image,
required this.description,
required this.fee,
required this.discountedFee,
required this.bookingFee,
required this.visitDay,
required this.timeFrom,
required this.timeTo,
});
String encDietId;
String dietName;
dynamic email;
dynamic phone;
dynamic alternatePhone;
String image;
dynamic description;
dynamic fee;
dynamic discountedFee;
dynamic bookingFee;
dynamic visitDay;
dynamic timeFrom;
dynamic timeTo;
factory Data.fromJson(Map<String, dynamic> json) => Data(
encDietId: json["EncDietId"],
dietName: json["DietName"],
email: json["Email"],
phone: json["Phone"],
alternatePhone: json["AlternatePhone"],
image: json["Image"],
description: json["Description"],
fee: json["Fee"],
discountedFee: json["DiscountedFee"],
bookingFee: json["BookingFee"],
visitDay: json["VisitDay"],
timeFrom: json["TimeFrom"],
timeTo: json["TimeTo"],
);
Map<String, dynamic> toJson() => {
"EncDietId": encDietId,
"DietName": dietName,
"Email": email,
"Phone": phone,
"AlternatePhone": alternatePhone,
"Image": image,
"Description": description,
"Fee": fee,
"DiscountedFee": discountedFee,
"BookingFee": bookingFee,
"VisitDay": visitDay,
"TimeFrom": timeFrom,
"TimeTo": timeTo,
};
}
class PartnerDatum {
PartnerDatum({
required this.partnerId,
required this.encPartnerId,
required this.partnerName,
required this.partnerAddress,
required this.fee,
required this.discountedFee,
required this.bookingFee,
required this.dayList,
});
String partnerId;
String encPartnerId;
String partnerName;
String partnerAddress;
String fee;
String discountedFee;
String bookingFee;
List<DayList> dayList;
factory PartnerDatum.fromJson(Map<String, dynamic> json) => PartnerDatum(
partnerId: json["PartnerId"],
encPartnerId: json["EncPartnerId"],
partnerName: json["PartnerName"],
partnerAddress: json["PartnerAddress"],
fee: json["Fee"],
discountedFee: json["DiscountedFee"],
bookingFee: json["BookingFee"],
dayList: List<DayList>.from(json["DayList"].map((x) => DayList.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"PartnerId": partnerId,
"EncPartnerId": encPartnerId,
"PartnerName": partnerName,
"PartnerAddress": partnerAddress,
"Fee": fee,
"DiscountedFee": discountedFee,
"BookingFee": bookingFee,
"DayList": List<dynamic>.from(dayList.map((x) => x.toJson())),
};
}
class DayList {
DayList({
required this.dayName,
required this.timeFrom,
required this.timeTo,
});
String dayName;
String timeFrom;
String timeTo;
factory DayList.fromJson(Map<String, dynamic> json) => DayList(
dayName: json["DayName"],
timeFrom: json["TimeFrom"],
timeTo: json["TimeTo"],
);
Map<String, dynamic> toJson() => {
"DayName": dayName,
"TimeFrom": timeFrom,
"TimeTo": timeTo,
};
}
try below code hope its helpful to you
You can use string indexes to access these properties:
print(result['PartnerData'][0]['PartnerName']); // Rasomoy pvt. Hospital
print(result['PartnerData'][0]['PartnerAddress']); // Kol,Kol,Kol,Wb
Now go to Flutter documentation here:
The documentation also refers to the such model classes here :

How to store complex json data in model class in flutter

Here is my code"
I've tried printing values.
I got value in token.
I'm able to iterate through the each value present in API using for each loop but data isn't storing into my model class.
SharedPreferences prefs = await SharedPreferences.getInstance();
final token = prefs.getString("token") ?? null;
final userId = prefs.getInt("id") ?? null;
List<GroupListData> grpDataList = [];
if (token != null) {
String url = "${NetworkRequest.baseUrl}/api/group_list";
var groupRes = await http.post(Uri.parse(url), body: {
"user_id": '$userId'
}, headers: {
//'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
});
//print(groupRes.body);
if (groupRes.statusCode == 200) {
final rowJsonData = jsonDecode(groupRes.body);
GroupListData groupListData;
List<dynamic> groupLists = rowJsonData['data'];
groupLists.forEach((d) {
print(d['id']);
groupListData = GroupListData(
id: d['id'],
groupName: d["groupName"],
status: d["status"],
createdAt: d["createdAt"],
updatedAt: d["updatedAt"],
);
grpDataList.add(groupListData);
});
for (var d in rowJsonData['data']) {
print(d);
}
} else {
print('grpResp ${groupRes.statusCode}');
}
//print('Token : $token');
} else {
print('token is empty');
}
print(grpDataList);
return grpDataList;
}
here this is my JSON Data
{
"data": [
{
"id": 1,
"group_name": "payroll",
"status": 1,
"created_at": "2021-07-20 08:27:31",
"updated_at": "2021-07-20 10:09:11"
},
{
"id": 2,
"group_name": "New Recuritment",
"status": 1,
"created_at": "2021-07-20 11:21:40",
"updated_at": "2021-07-20 11:21:40"
}
],
"message": "Data Found",
"status": 200
}
here is my model class
i think that there is issue in my model class
i am not able to understand
class GroupListData {
GroupListData({
this.id,
this.groupName,
this.status,
this.createdAt,
this.updatedAt,
});
int? id;
String? groupName;
int? status;
DateTime? createdAt;
DateTime? updatedAt;
factory GroupListData.fromJson(Map<String, dynamic> json) => GroupListData(
id: json["id"],
groupName: json["group_name"],
status: json["status"],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
);
Map<String, dynamic> toJson() => {
"id": id,
"group_name": groupName,
"status": status,
"created_at": createdAt!.toIso8601String(),
"updated_at": updatedAt!.toIso8601String(),
};
}
here is my ui code
FutureBuilder<List<GroupListData>>(
future: getGroupListData(),
builder: (BuildContext context,
AsyncSnapshot<List<GroupListData>> snapshot) {
if (snapshot.data == null) {
return Container(
child: Center(
child: Text('Loading...'),
),
);
}
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: snapshot.data!.length,
itemBuilder: (BuildContext context, int index) {
return RoundedCard(
str: '${snapshot.data![index].groupName}', ///.groupName always return null value
onTap: () {
Navigator.push(
context,
PageTransition(
type: PageTransitionType.rightToLeft,
child: FeedPage(feedTitle: 'Marketing Team'),
inheritTheme: true,
ctx: context),
);
print('Marketing card');
});
});
},
),
thanks in advance
You dont need to convert your json to modal by yourself.
if the Flutter SDK < 2.0 (Null safety) then please use this online json converter https://javiercbk.github.io/json_to_dart/
otherwise use this online json Converter for Flutter > 2.0 https://app.quicktype.io/

Flutter fetch data from the internet

I'm trying to get some information from here such as name,avatar_url,stargazers_count and description
{
"total_count": 18689015,
"incomplete_results": true,
"items": [
{
"id": 215415332,
"node_id": "MDEwOlJlcG9zaXRvcnkyMTU0MTUzMzI=",
"name": "HackingNeuralNetworks",
"full_name": "Kayzaks/HackingNeuralNetworks",
"private": false,
"owner": {
"login": "Kayzaks",
"id": 11071537,
"node_id": "MDQ6VXNlcjExMDcxNTM3",
"avatar_url": "https://avatars1.githubusercontent.com/u/11071537?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Kayzaks",
"html_url": "https://github.com/Kayzaks",
"followers_url": "https://api.github.com/users/Kayzaks/followers",
"following_url": "https://api.github.com/users/Kayzaks/following{/other_user}",
"gists_url": "https://api.github.com/users/Kayzaks/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Kayzaks/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Kayzaks/subscriptions",
"organizations_url": "https://api.github.com/users/Kayzaks/orgs",
"repos_url": "https://api.github.com/users/Kayzaks/repos",
"events_url": "https://api.github.com/users/Kayzaks/events{/privacy}",
"received_events_url": "https://api.github.com/users/Kayzaks/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/Kayzaks/HackingNeuralNetworks",
"description": "A small course on exploiting and defending neural networks",
"fork": false,
....
....
At run time I get this message error :
type _internalLine HashMap<String , dynamic> is not a subtype of type List<dynamic> in type cast
here's the full code :
RepoItem:
class RepoItem {
Owner owner;
String name;
String stargazers_count;
String description;
RepoItem._({this.owner, this.name, this.stargazers_count, this.description});
factory RepoItem.fromJson(Map<String, dynamic> json) {
return new RepoItem._(
owner: json['owner'],
name: json['name'],
stargazers_count: json['stargazers_count'],
description: json['description']);
}
}
PageState:
class _MyHomePageState extends State<MyHomePage> {
List<RepoItem> list = List();
var isLoading = false;
Future<List<RepoItem>> _fetchData() async {
final response = await http.get(
"https://api.github.com/search/repositories?q=created:%3E2018-10-22&sort=stars&order=desc");
list = (json.decode(response.body) as List)
.map((data) => new RepoItem.fromJson(data.body))
.toList();
return list;
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
child: FutureBuilder(
future: _fetchData(),
builder: (BuildContext context, AsyncSnapshot asyncSnapshot) {
if (asyncSnapshot.hasError) {
return Container(
child: Center(
child: Text(asyncSnapshot.error.toString()),
),
);
}
if (asyncSnapshot.data == null) {
return Container(
child: Center(
child: Text("Loading ..."),
),
);
} else {
return ListView.builder(
itemCount: asyncSnapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(asyncSnapshot.data[index].name),
leading: CircleAvatar(
backgroundImage: NetworkImage(
asyncSnapshot.data[index].owner.avatar_url),
),
subtitle: Text(asyncSnapshot.data[index].description),
);
},
);
}
},
),
),
);
}
}
You can copy paste run full code below
You can parse with payloadFromJson, you can see Payload class in full code
Payload payloadFromJson(String str) => Payload.fromJson(json.decode(str));
...
var items = snapshot.data.items;
return ListView.builder(
itemCount: items.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(items[index].name),
leading: CircleAvatar(
backgroundImage:
NetworkImage(items[index].owner.avatarUrl),
),
subtitle: Text(items[index].description),
);
},
);
working demo
full code
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
// To parse this JSON data, do
//
// final payload = payloadFromJson(jsonString);
import 'dart:convert';
Payload payloadFromJson(String str) => Payload.fromJson(json.decode(str));
String payloadToJson(Payload data) => json.encode(data.toJson());
class Payload {
String totalCount;
bool incompleteResults;
List<Item> items;
Payload({
this.totalCount,
this.incompleteResults,
this.items,
});
factory Payload.fromJson(Map<String, dynamic> json) => Payload(
totalCount: json["total_count"].toString(),
incompleteResults: json["incomplete_results"],
items: List<Item>.from(json["items"].map((x) => Item.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"total_count": totalCount,
"incomplete_results": incompleteResults,
"items": List<dynamic>.from(items.map((x) => x.toJson())),
};
}
class Item {
String id;
String nodeId;
String name;
String fullName;
bool private;
Owner owner;
String htmlUrl;
String description;
bool fork;
String url;
String forksUrl;
String keysUrl;
String collaboratorsUrl;
String teamsUrl;
String hooksUrl;
String issueEventsUrl;
String eventsUrl;
String assigneesUrl;
String branchesUrl;
String tagsUrl;
String blobsUrl;
String gitTagsUrl;
String gitRefsUrl;
String treesUrl;
String statusesUrl;
String languagesUrl;
String stargazersUrl;
String contributorsUrl;
String subscribersUrl;
String subscriptionUrl;
String commitsUrl;
String gitCommitsUrl;
String commentsUrl;
String issueCommentUrl;
String contentsUrl;
String compareUrl;
String mergesUrl;
String archiveUrl;
String downloadsUrl;
String issuesUrl;
String pullsUrl;
String milestonesUrl;
String notificationsUrl;
String labelsUrl;
String releasesUrl;
String deploymentsUrl;
DateTime createdAt;
DateTime updatedAt;
DateTime pushedAt;
String gitUrl;
String sshUrl;
String cloneUrl;
String svnUrl;
String homepage;
int size;
int stargazersCount;
int watchersCount;
String language;
bool hasIssues;
bool hasProjects;
bool hasDownloads;
bool hasWiki;
bool hasPages;
int forksCount;
dynamic mirrorUrl;
bool archived;
bool disabled;
int openIssuesCount;
License license;
int forks;
int openIssues;
int watchers;
DefaultBranch defaultBranch;
double score;
Item({
this.id,
this.nodeId,
this.name,
this.fullName,
this.private,
this.owner,
this.htmlUrl,
this.description,
this.fork,
this.url,
this.forksUrl,
this.keysUrl,
this.collaboratorsUrl,
this.teamsUrl,
this.hooksUrl,
this.issueEventsUrl,
this.eventsUrl,
this.assigneesUrl,
this.branchesUrl,
this.tagsUrl,
this.blobsUrl,
this.gitTagsUrl,
this.gitRefsUrl,
this.treesUrl,
this.statusesUrl,
this.languagesUrl,
this.stargazersUrl,
this.contributorsUrl,
this.subscribersUrl,
this.subscriptionUrl,
this.commitsUrl,
this.gitCommitsUrl,
this.commentsUrl,
this.issueCommentUrl,
this.contentsUrl,
this.compareUrl,
this.mergesUrl,
this.archiveUrl,
this.downloadsUrl,
this.issuesUrl,
this.pullsUrl,
this.milestonesUrl,
this.notificationsUrl,
this.labelsUrl,
this.releasesUrl,
this.deploymentsUrl,
this.createdAt,
this.updatedAt,
this.pushedAt,
this.gitUrl,
this.sshUrl,
this.cloneUrl,
this.svnUrl,
this.homepage,
this.size,
this.stargazersCount,
this.watchersCount,
this.language,
this.hasIssues,
this.hasProjects,
this.hasDownloads,
this.hasWiki,
this.hasPages,
this.forksCount,
this.mirrorUrl,
this.archived,
this.disabled,
this.openIssuesCount,
this.license,
this.forks,
this.openIssues,
this.watchers,
this.defaultBranch,
this.score,
});
factory Item.fromJson(Map<String, dynamic> json) => Item(
id: json["id"].toString(),
nodeId: json["node_id"],
name: json["name"],
fullName: json["full_name"],
private: json["private"],
owner: Owner.fromJson(json["owner"]),
htmlUrl: json["html_url"],
description: json["description"] == null ? null : json["description"],
fork: json["fork"],
url: json["url"],
forksUrl: json["forks_url"],
keysUrl: json["keys_url"],
collaboratorsUrl: json["collaborators_url"],
teamsUrl: json["teams_url"],
hooksUrl: json["hooks_url"],
issueEventsUrl: json["issue_events_url"],
eventsUrl: json["events_url"],
assigneesUrl: json["assignees_url"],
branchesUrl: json["branches_url"],
tagsUrl: json["tags_url"],
blobsUrl: json["blobs_url"],
gitTagsUrl: json["git_tags_url"],
gitRefsUrl: json["git_refs_url"],
treesUrl: json["trees_url"],
statusesUrl: json["statuses_url"],
languagesUrl: json["languages_url"],
stargazersUrl: json["stargazers_url"],
contributorsUrl: json["contributors_url"],
subscribersUrl: json["subscribers_url"],
subscriptionUrl: json["subscription_url"],
commitsUrl: json["commits_url"],
gitCommitsUrl: json["git_commits_url"],
commentsUrl: json["comments_url"],
issueCommentUrl: json["issue_comment_url"],
contentsUrl: json["contents_url"],
compareUrl: json["compare_url"],
mergesUrl: json["merges_url"],
archiveUrl: json["archive_url"],
downloadsUrl: json["downloads_url"],
issuesUrl: json["issues_url"],
pullsUrl: json["pulls_url"],
milestonesUrl: json["milestones_url"],
notificationsUrl: json["notifications_url"],
labelsUrl: json["labels_url"],
releasesUrl: json["releases_url"],
deploymentsUrl: json["deployments_url"],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
pushedAt: DateTime.parse(json["pushed_at"]),
gitUrl: json["git_url"],
sshUrl: json["ssh_url"],
cloneUrl: json["clone_url"],
svnUrl: json["svn_url"],
homepage: json["homepage"] == null ? null : json["homepage"],
size: json["size"],
stargazersCount: json["stargazers_count"],
watchersCount: json["watchers_count"],
language: json["language"] == null ? null : json["language"],
hasIssues: json["has_issues"],
hasProjects: json["has_projects"],
hasDownloads: json["has_downloads"],
hasWiki: json["has_wiki"],
hasPages: json["has_pages"],
forksCount: json["forks_count"],
mirrorUrl: json["mirror_url"],
archived: json["archived"],
disabled: json["disabled"],
openIssuesCount: json["open_issues_count"],
license:
json["license"] == null ? null : License.fromJson(json["license"]),
forks: json["forks"],
openIssues: json["open_issues"],
watchers: json["watchers"],
defaultBranch: defaultBranchValues.map[json["default_branch"]],
score: json["score"],
);
Map<String, dynamic> toJson() => {
"id": id,
"node_id": nodeId,
"name": name,
"full_name": fullName,
"private": private,
"owner": owner.toJson(),
"html_url": htmlUrl,
"description": description == null ? null : description,
"fork": fork,
"url": url,
"forks_url": forksUrl,
"keys_url": keysUrl,
"collaborators_url": collaboratorsUrl,
"teams_url": teamsUrl,
"hooks_url": hooksUrl,
"issue_events_url": issueEventsUrl,
"events_url": eventsUrl,
"assignees_url": assigneesUrl,
"branches_url": branchesUrl,
"tags_url": tagsUrl,
"blobs_url": blobsUrl,
"git_tags_url": gitTagsUrl,
"git_refs_url": gitRefsUrl,
"trees_url": treesUrl,
"statuses_url": statusesUrl,
"languages_url": languagesUrl,
"stargazers_url": stargazersUrl,
"contributors_url": contributorsUrl,
"subscribers_url": subscribersUrl,
"subscription_url": subscriptionUrl,
"commits_url": commitsUrl,
"git_commits_url": gitCommitsUrl,
"comments_url": commentsUrl,
"issue_comment_url": issueCommentUrl,
"contents_url": contentsUrl,
"compare_url": compareUrl,
"merges_url": mergesUrl,
"archive_url": archiveUrl,
"downloads_url": downloadsUrl,
"issues_url": issuesUrl,
"pulls_url": pullsUrl,
"milestones_url": milestonesUrl,
"notifications_url": notificationsUrl,
"labels_url": labelsUrl,
"releases_url": releasesUrl,
"deployments_url": deploymentsUrl,
"created_at": createdAt.toIso8601String(),
"updated_at": updatedAt.toIso8601String(),
"pushed_at": pushedAt.toIso8601String(),
"git_url": gitUrl,
"ssh_url": sshUrl,
"clone_url": cloneUrl,
"svn_url": svnUrl,
"homepage": homepage == null ? null : homepage,
"size": size,
"stargazers_count": stargazersCount,
"watchers_count": watchersCount,
"language": language == null ? null : language,
"has_issues": hasIssues,
"has_projects": hasProjects,
"has_downloads": hasDownloads,
"has_wiki": hasWiki,
"has_pages": hasPages,
"forks_count": forksCount,
"mirror_url": mirrorUrl,
"archived": archived,
"disabled": disabled,
"open_issues_count": openIssuesCount,
"license": license == null ? null : license.toJson(),
"forks": forks,
"open_issues": openIssues,
"watchers": watchers,
"default_branch": defaultBranchValues.reverse[defaultBranch],
"score": score,
};
}
enum DefaultBranch { MASTER }
final defaultBranchValues = EnumValues({"master": DefaultBranch.MASTER});
class License {
String key;
String name;
String spdxId;
String url;
String nodeId;
License({
this.key,
this.name,
this.spdxId,
this.url,
this.nodeId,
});
factory License.fromJson(Map<String, dynamic> json) => License(
key: json["key"],
name: json["name"],
spdxId: json["spdx_id"],
url: json["url"] == null ? null : json["url"],
nodeId: json["node_id"],
);
Map<String, dynamic> toJson() => {
"key": key,
"name": name,
"spdx_id": spdxId,
"url": url == null ? null : url,
"node_id": nodeId,
};
}
class Owner {
String login;
String id;
String nodeId;
String avatarUrl;
String gravatarId;
String url;
String htmlUrl;
String followersUrl;
String followingUrl;
String gistsUrl;
String starredUrl;
String subscriptionsUrl;
String organizationsUrl;
String reposUrl;
String eventsUrl;
String receivedEventsUrl;
Type type;
bool siteAdmin;
Owner({
this.login,
this.id,
this.nodeId,
this.avatarUrl,
this.gravatarId,
this.url,
this.htmlUrl,
this.followersUrl,
this.followingUrl,
this.gistsUrl,
this.starredUrl,
this.subscriptionsUrl,
this.organizationsUrl,
this.reposUrl,
this.eventsUrl,
this.receivedEventsUrl,
this.type,
this.siteAdmin,
});
factory Owner.fromJson(Map<String, dynamic> json) => Owner(
login: json["login"],
id: json["id"].toString(),
nodeId: json["node_id"],
avatarUrl: json["avatar_url"],
gravatarId: json["gravatar_id"],
url: json["url"],
htmlUrl: json["html_url"],
followersUrl: json["followers_url"],
followingUrl: json["following_url"],
gistsUrl: json["gists_url"],
starredUrl: json["starred_url"],
subscriptionsUrl: json["subscriptions_url"],
organizationsUrl: json["organizations_url"],
reposUrl: json["repos_url"],
eventsUrl: json["events_url"],
receivedEventsUrl: json["received_events_url"],
type: typeValues.map[json["type"]],
siteAdmin: json["site_admin"],
);
Map<String, dynamic> toJson() => {
"login": login,
"id": id,
"node_id": nodeId,
"avatar_url": avatarUrl,
"gravatar_id": gravatarId,
"url": url,
"html_url": htmlUrl,
"followers_url": followersUrl,
"following_url": followingUrl,
"gists_url": gistsUrl,
"starred_url": starredUrl,
"subscriptions_url": subscriptionsUrl,
"organizations_url": organizationsUrl,
"repos_url": reposUrl,
"events_url": eventsUrl,
"received_events_url": receivedEventsUrl,
"type": typeValues.reverse[type],
"site_admin": siteAdmin,
};
}
enum Type { USER, ORGANIZATION }
final typeValues =
EnumValues({"Organization": Type.ORGANIZATION, "User": Type.USER});
class EnumValues<T> {
Map<String, T> map;
Map<T, String> reverseMap;
EnumValues(this.map);
Map<T, String> get reverse {
if (reverseMap == null) {
reverseMap = map.map((k, v) => new MapEntry(v, k));
}
return reverseMap;
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
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> {
static final String URL = "https://corona.lmao.ninja/countries";
Future _future;
Future<Payload> _fetchData() async {
final response = await http.get(
"https://api.github.com/search/repositories?q=created:%3E2018-10-22&sort=stars&order=desc");
var list = payloadFromJson(response.body);
return list;
}
#override
void initState() {
// TODO: implement initState
super.initState();
_future = _fetchData();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: FutureBuilder<Payload>(
future: _future,
builder: (BuildContext context, AsyncSnapshot<Payload> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
return Text('Input a URL to start');
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 {
var items = snapshot.data.items;
return ListView.builder(
itemCount: items.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(items[index].name),
leading: CircleAvatar(
backgroundImage:
NetworkImage(items[index].owner.avatarUrl),
),
subtitle: Text(items[index].description),
);
},
);
}
}
}));
}
}