简体   繁体   English

未处理的异常:类型 '_InternalLinkedHashMap<string, dynamic> ' 不是类型 'List 的子类型<dynamic> '</dynamic></string,>

[英]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.

相关问题 sFlutter 未处理的异常:InternalLinkedHashMap<string, dynamic> ' 不是类型 'List 的子类型<dynamic></dynamic></string,> - sFlutter Unhandled Exception : InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic> 未处理的异常:InternalLinkedHashMap<string, dynamic> ' 不是类型 'List 的子类型<dynamic></dynamic></string,> - Unhandled Exception: InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic> 未处理的异常:键入&#39;_InternalLinkedHashMap <String, dynamic> &#39;不是&#39;Future类型的子类型 <dynamic> &#39; - Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Future<dynamic>' 未处理的异常:类型 &#39;_InternalLinkedHashMap<String, dynamic> &#39; 不是 &#39;Iterable 类型的子类型<dynamic> &#39; - Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Iterable<dynamic>' 未处理的异常:类型 '_InternalLinkedHashMap<string, dynamic> ' 不是类型 'String' 的子类型</string,> - Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String' 未处理的异常:类型 &#39;_InternalLinkedHashMap<String, dynamic> &#39; 不是 &#39;String 类型的子类型 - Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String 未处理的异常:[type '_InternalLinkedHashMap<string, dynamic> ' 不是 'String' 类型的子类型]</string,> - Unhandled exception: [type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'] 未处理的异常:类型 '_InternalLinkedHashMap<string, dynamic> ' 不是类型 'String' 的子类型</string,> - Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String' 颤振:未处理的异常:类型 &#39;_InternalLinkedHashMap<String, dynamic> &#39; 不是 &#39;String&#39; 类型的子类型 - Flutter: Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String' 未处理的异常:类型 '_InternalLinkedHashMap<string, dynamic> ' 不是类型 'List 的子类型<dynamic> ' 在类型转换中</dynamic></string,> - Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>' in type cast
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM