[英]Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>'
I try to fetch data from apis to my Flutter app and i get this error.我尝试从 api 获取数据到我的 Flutter 应用程序,但出现此错误。 I want to display some things in my home page with my getDashboardItems function after i log in.
我想在登录后使用 getDashboardItems function 在我的主页中显示一些内容。
network.dart网络.dart
Future<List> getDashboardItems() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var accessToken = "Token ${prefs.getString("accessToken")!}";
final response = await get(
Uri.parse('$baseUrlApi/employee-api/dashboard/'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': accessToken,
},
);
repository.dart存储库.dart
Future<List> getDashboardItem() async {
final signUpData = await networkService.getDashboardItems();
if (signUpData[0] == true) {
try {
return [true, signUpData[1]];
} catch (e) {
return [false, []];
}
}
return [false, signUpData[1]];
}
homecontroller.dart家庭控制器.dart
getDashboardItem(context) {
isLoading.value = true;
repository.getDashboardItem().then((res) {
if (res[0] == true) {
isLoading.value = false;
getDashboardResponse.value = res[1];
} else if (res[1]['detail'] == 'Invalid token.' ||
res[1]['detail'] == 'Authentication credentials were not provided') {
Get.snackbar('Error', 'Your session is out, Please login again',
snackPosition: SnackPosition.TOP);
logout(context);
} else {
isLoading.value = false;
Get.snackbar('Error', res[1]['parameter error'],
snackPosition: SnackPosition.TOP);
}
});
}
When I get this error it sends my on the line当我收到此错误时,它会发送我的在线
getDashboardResponse.value = res[1];
from homecontroller.来自家庭控制器。
Its because you are trying to do this for example {"data":[]}(ie) this is your response data so res[1] is not possible to get a better understandment of what you are trying to best is it possible to share the response you are getting from the api这是因为您正在尝试这样做,例如 {"data":[]}(ie) 这是您的响应数据,因此 res[1] 无法更好地了解您正在努力做到最好的是有可能分享您从 api 获得的回复
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.