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