che*_*jan 5 web flutter flutter-web
我正在尝试在 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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
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
Run Code Online (Sandbox Code Playgroud)
不太确定是什么导致了这个问题,希望你能帮忙。谢谢你。
我的 Flutter Web 应用程序与 Azure Function 进行通信。iOS 和 Android 版本运行良好,但我得到的是property 'Symbol(dartx._get)' of null尝试针对 flutter web 中的 azure 函数执行 graphql 查询时,出现了上述错误。上面评论中 Chetan 的 CORS 提示给了我一个线索。
这个 Stack Overflow 问答解决了我在生产和本地主机上遇到的问题。来自本地主机(而非 CLI)的具有 Azure 功能的 CORS