简体   繁体   English

Flutter:未处理的异常:类型“(动态)=> void”不是“动作”类型“(字符串,动态)=> void”的子类型

[英]Flutter : Unhandled Exception: type '(dynamic) => void' is not a subtype of type '(String, dynamic) => void' of 'action'

Full Error:完全错误:

`E/flutter (15265): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: type '(dynamic) => void' is not a subtype of type '(String, dynamic) => void' of 'action' E/flutter (15265): #0 OrderController.getOrderDetails (package:mart/controller/order_controller.dart:117:23) E/flutter (15265): E/flutter (15265): D/ViewRootImplMainActivity: windowFocusChanged hasFocus=false inTouchMode=true `E/flutter (15265): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] 未处理的异常:类型“(动态)=> void”不是类型“(字符串,动态)=> 'action' 无效' E/flutter (15265): #0 OrderController.getOrderDetails (package:mart/controller/order_controller.dart:117:23) E/flutter (15265): E/flutter (15265): D/ViewRootImplMainActivity : windowFocusChanged hasFocus=false inTouchMode=true

error:错误:

Future<List<OrderDetailsModel>> getOrderDetails(String orderID) async {
    _orderDetails = null;
    _isLoading = true;
    _showCancelled = false;

    if(_trackModel == null || _trackModel.orderType != 'parcel') {
      Response response = await orderRepo.getOrderDetails(orderID);
      _isLoading = false;
      if (response.statusCode == 200) {
        _orderDetails = [];
        response.body.forEach((orderDetail) => _orderDetails.add(OrderDetailsModel.fromJson(orderDetail)));
      } else {
        ApiChecker.checkApi(response);
      }
    }else {
      _isLoading = false;
      _orderDetails = [];
    }

UPDATE更新

void _loadData(BuildContext context, bool reload) async {
    await Get.find<OrderController>().trackOrder(widget.orderId.toString(), reload ? null : widget.orderModel, false);
    if(widget.orderModel == null) {
      await Get.find<SplashController>().getConfigData();
    }
    Get.find<OrderController>().getOrderDetails(widget.orderId.toString());
  }

Your issue is in forEach in your getOrderDetails, you are doing it in wrong way.your json response is a map and map has key , value property您的问题出现在 getOrderDetails 中的 forEach 中,您的操作方式错误。您的 json 响应是 map 和 map 具有key , value属性

response.body.forEach((key, value) => _orderDetails.add(OrderDetailsModel.fromJson(value)));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter - 未处理的异常:类型“(dynamic) => Null”不是“f”的类型“(String, dynamic) => void”的子类型 - Flutter - Unhandled Exception: type '(dynamic) => Null' is not a subtype of type '(String, dynamic) => void' of 'f' Flutter:异常:类型 &#39;(dynamic, dynamic, dynamic) =&gt; void&#39; 不是类型 &#39;(String, dynamic) =&gt; void&#39; 的子类型 &#39;f&#39; - Flutter: Exception: type '(dynamic, dynamic, dynamic) => void' is not a subtype of type '(String, dynamic) => void' of 'f' type '(String) =&gt; void' 不是类型 '(dynamic) =&gt; void' 的子类型 - type '(String) => void' is not a subtype of type '(dynamic) => void' 未处理的异常:类型“(动态)=&gt; Null”不是数据 model 中“f”类型“(字符串,动态)=&gt; void”的子类型 - Unhandled Exception: type '(dynamic) => Null' is not a subtype of type '(String, dynamic) => void' of 'f' in the Data model 在列表中<user> users = [] ------ 未处理的异常:类型 '(dynamic) =&gt; Null' 不是类型 '(String, dynamic) =&gt; void' of 'f' 的子类型</user> - in List<User> users = [] ------ Unhandled Exception: type '(dynamic) => Null' is not a subtype of type '(String, dynamic) => void' of 'f' 输入'未来<dynamic> ' 不是类型 '() =&gt; void' flutter 的子类型</dynamic> - type 'Future<dynamic>' is not a subtype of type '() => void' flutter 未处理的异常:输入“未来”<dynamic> ' 不是类型 'String' 的子类型:Flutter 异常</dynamic> - Unhandled Exception: type 'Future<dynamic>' is not a subtype of type 'String' : Flutter Exception 颤振:未处理的异常:类型 &#39;_InternalLinkedHashMap<String, dynamic> &#39; 不是 &#39;String&#39; 类型的子类型 - Flutter: Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String' 未处理的异常:“字符串”类型不是“地图”类型的子类型<string, dynamic> flutter</string,> - Unhandled Exception: type 'String' is not a subtype of type 'Map<String, dynamic> flutter Flutter:未处理的异常:类型“String”不是类型“Map”的子类型<string, dynamic> '</string,> - Flutter: Unhandled Exception: type 'String' is not a subtype of type 'Map<String, dynamic>'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM