无法读取 null 的 属性 'Symbol(dartx._get)'
Cannot read property 'Symbol(dartx._get)' of null
我试图在 Web 应用程序中调用 API 时显示此错误,并且 Android 和 iOS 工作正常。我不明白为什么 happening.I 使用改装和 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
不太确定到底是什么导致了这个问题,希望您能提供帮助。
非常感谢。
CORS 相关问题
我的 Flutter Web 应用程序与 Azure 函数通信。 iOS 和 Android 版本工作正常,但是当我尝试在 flutter web 中针对 azure 函数执行 graphql 查询时,我遇到了上面的 property 'Symbol(dartx._get)' of null
错误。上面评论中 Chetan 的 CORS 提示给了我一个线索。
这个 Stack Overflow Q&A 解决了我在生产和本地主机上遇到的问题。 CORS with Azure function from localhost (not CLI)
- Localhost Solution
- Production Solution
有时可能是由于未初始化的Map Fields on set operation,
所以初始化它,
Map<String> jsonResult;
到
Map<String> jsonResult={};
我收到与 Flutter 网络上的 file_picker 库相关的错误。
空引用在 FilePickerResult 结果对象中。 result.files.single.path
这 returns 在 Flutter web 上为 null,但由于某种原因在任何其他平台上都不是。
如果是这种情况,您可能需要进行如下更改才能解决问题:
FilePickerResult uploadfile = File(result.files.single.path);
至:
Uint8List uploadfile = result.files.single.bytes;
我从这个答案中找到了解决方案,所以一切归功于他:
谢谢!
我试图在 Web 应用程序中调用 API 时显示此错误,并且 Android 和 iOS 工作正常。我不明白为什么 happening.I 使用改装和 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
不太确定到底是什么导致了这个问题,希望您能提供帮助。 非常感谢。
CORS 相关问题
我的 Flutter Web 应用程序与 Azure 函数通信。 iOS 和 Android 版本工作正常,但是当我尝试在 flutter web 中针对 azure 函数执行 graphql 查询时,我遇到了上面的 property 'Symbol(dartx._get)' of null
错误。上面评论中 Chetan 的 CORS 提示给了我一个线索。
这个 Stack Overflow Q&A 解决了我在生产和本地主机上遇到的问题。 CORS with Azure function from localhost (not CLI)
- Localhost Solution
- Production Solution
有时可能是由于未初始化的Map Fields on set operation, 所以初始化它,
Map<String> jsonResult;
到
Map<String> jsonResult={};
我收到与 Flutter 网络上的 file_picker 库相关的错误。
空引用在 FilePickerResult 结果对象中。 result.files.single.path
这 returns 在 Flutter web 上为 null,但由于某种原因在任何其他平台上都不是。
如果是这种情况,您可能需要进行如下更改才能解决问题:
FilePickerResult uploadfile = File(result.files.single.path);
至:
Uint8List uploadfile = result.files.single.bytes;
我从这个答案中找到了解决方案,所以一切归功于他:
谢谢!