I am calling an API to get data from server and i try make a dart file (model). after get in a field value and all data show list. but i cannot found how to make. i was try many options but always take a syntax error or diffrent errors. my getdata work i can print console but can't take in value. have a easy way?
my json;
{
"success": true,
"message": "User List",
"data": [
{
"user_name": "user1",
"user_f_name": "User",
"comp_type": "AGN",
"comp_depr": "SALES",
"comp_code": "AHN0001",
"depr_job": "",
"comp_code_sub": "",
"private_1": "",
"private_2": "",
"create_user": "",
"update_user": "",
"created_at": 2021-09-06T21:01:01.000000Z,
"updated_at": "2021-09-06T21:01:01.000000Z",
"id": 0
},
{
"user_name": "user2",
"user_f_name": "",
"comp_type": "",
"comp_depr": "",
"comp_code": "",
"depr_job": "",
"comp_code_sub": "",
"private_1": "",
"private_2": "",
"create_user": "",
"update_user": "",
"created_at": "2021-09-06T20:49:45.000000Z",
"updated_at": "2021-09-06T20:49:45.000000Z",
"id": 0
}
]
}
my code try one data;
Future<Map<String, dynamic>> getData3() async {
final prefs = await SharedPreferences.getInstance();
final key = 'token';
final value = prefs.get(key) ?? 0;
final prefsu = await SharedPreferences.getInstance();
final keyu = 'user';
final valueu = prefsu.get(keyu) ?? 0;
var username = "$valueu";
String myUrl =
String myUrl = "$serverUrl/userchecks/$username";
http.Response response = await http.get(Uri.parse(myUrl), headers: {
'Accept': 'application/json',
'Authorization': 'Bearer $value'
});
var data1 = json.decode(response.body);
print('Response status : ${response.statusCode}');
print(json.decode(response.body));
print(data1['user_f_name']);
return (json.decode(response.body));
}
my code try list data
Future<Map<String, dynamic>> getData() async {
final prefs = await SharedPreferences.getInstance();
final key = 'token';
final value = prefs.get(key) ?? 0;
String myUrl = "$serverUrl/userchecks";
http.Response response = await http.get(Uri.parse(myUrl), headers: {
'Accept': 'application/json',
'Authorization': 'Bearer $value'
});
print('Response status : ${response.statusCode}');
print(json.decode(response.body));
final data1 = json.decode(response.body);
print(data1['user_f_name']);
return json.decode(response.body);
}