I'm trying to get the data to display in List view but unfortunately i'm facing the error as the snapshot return empty values
Below is the code for my API
static Future<List<Permission>> getPermissionData() async {
String ruhusa = 'permission';
var response = await http.get(mainUrl + ruhusa,
headers: setHeader(accessKey.accessKey));
List<Permission> permissions = [];
if(response.statusCode == 200){
print(response.statusCode);
Map<String, dynamic> body = jsonDecode(response.body);
// print(response.body);
for(var item in body['msg']){
Permission permission = Permission.fromJson(item);
permissions.add(permission);
// return permissions;
}
return permissions;
}
// print(permissions);
return permissions;
}
This is the code where i want to display using future builder
body: FutureBuilder(
future: PermissionService.getPermissionData(),
builder: (BuildContext context, AsyncSnapshot<List<Permission>> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot != null) {
print("This is ${snapshot.data}");
return ListView.builder(
itemCount: snapshot.data?.length ?? 0,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
Navigator.pushNamed(context, permissionSpecificRoute,
arguments: snapshot.data[index]);
},
child: PermissionCard(
permission: snapshot.data[index],
),
);
},
);
} else if(snapshot.hasError) {
return Center(child: Text("Oops error issues is ${snapshot.hasError}"));
}
else {
return Center(child: Text('No permissions requested'));
}
} else {
return PageLoader();
}
},
),
When I try to print it in my console it return
This is []
Anyone who can help please what should i do to make the snapshot receive the real data
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…