【发布时间】:2021-02-25 17:09:29
【问题描述】:
我正在尝试在 Web 应用程序中调用 API 以显示此错误并且 Android 和 iOS 工作正常。我不明白为什么会发生。我正在使用改造和 dio 来调用 api。
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:web_app/utils/constants.dart';
class ServiceError {
static BuildContext context;
ServiceError(BuildContext context) {
context = context;
}
void getError(final res) {
print("MyError" + res.toString()); // I got null value and this working fine in android and iOS. only i get problem in web app
final jsonResponse = jsonDecode(res.toString());
ApiError apiError = ApiError.fromJson(jsonResponse);
print("MyError" + apiError.status);
print("MyCode" + apiError.message);
if (apiError.responseCode == 500) {
Constants.toast(apiError.message);
} else {
Constants.toast(apiError.message);
}
}
}
我收到了这个错误
TypeError: Cannot read property 'Symbol(dartx._get)' of null
at new service_errors.ApiError.fromJson (http://localhost:44059/packages/web_app/service_errors/service_errors.dart.lib.js:103:36)
at service_errors.ServiceError.new.getError (http://localhost:44059/packages/web_app/service_errors/service_errors.dart.lib.js:23:22)
at http://localhost:44059/packages/web_app/forgot_password/reset_password.dart.lib.js:6485:58
at _RootZone.runUnary (http://localhost:44059/dart_sdk.js:37533:58)
at _FutureListener.catchError.handleError (http://localhost:44059/dart_sdk.js:32521:48)
at handleError (http://localhost:44059/dart_sdk.js:33070:51)
at Function._propagateToListeners (http://localhost:44059/dart_sdk.js:33096:17)
at _Future.new.[_completeError] (http://localhost:44059/dart_sdk.js:32943:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:44059/dart_sdk.js:32981:31)
at Object._microtaskLoop (http://localhost:44059/dart_sdk.js:37794:13)
at _startMicrotaskLoop (http://localhost:44059/dart_sdk.js:37800:13)
at http://localhost:44059/dart_sdk.js:33309:9
不确定是什么导致了问题,希望您能提供帮助。 非常感谢。
【问题讨论】:
-
你能通过打印检查'res'的数据类型吗?
-
是的,我得到了 DioError 并得到空值。
-
你从哪里调用 getError?问题可能是在网络平台上传递的内容。
-
感谢 Lee3 和 Hoon 问题已解决。 CROS 问题。
-
@chetanmahajan - 你能详细说明并发布你的答案吗?我也遇到了 Flutter Web 的这个问题。
标签: flutter web flutter-web