![](/img/trans.png)
[英]Flutter - Unhandled Exception: type '(dynamic) => Null' is not a subtype of type '(String, dynamic) => void' of 'f'
[英]Flutter : Unhandled Exception: type '(dynamic) => void' is not a subtype of type '(String, dynamic) => void' of 'action'
完全錯誤:
`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
錯誤:
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 = [];
}
更新
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());
}
您的問題出現在 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.