【问题标题】:Cannot read property 'Symbol(dartx._get)' of null无法读取 null 的属性 'Symbol(dartx._get)'
【发布时间】: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


【解决方案1】:

CORS 相关问题

我的 Flutter Web 应用与 Azure Function 通信。 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)

【讨论】:

    【解决方案2】:

    有时可能是由于集合操作上未初始化的地图字段, 所以初始化它,

    Map<String> jsonResult;
    

    到

    Map<String> jsonResult={};
    

    【讨论】:

      【解决方案3】:

      我收到这个与 Flutter web 上的 file_picker 库有关的错误。

      空引用位于 FilePickerResult 结果对象中。 result.files.single.path 这在 Flutter web 上返回 null,但由于某种原因在任何其他平台上都不返回。

      如果是这种情况,您可能需要更改以下内容来解决问题:

      FilePickerResult uploadfile = File(result.files.single.path);
      

      到:

      Uint8List uploadfile = result.files.single.bytes;
      

      我从这个答案中找到了解决方案,所以全部归功于他:

      https://stackoverflow.com/a/65435068/5654210

      谢谢!

      【讨论】:

        猜你喜欢
        • 2021-04-09
        • 1970-01-01
        • 2021-03-09
        • 2019-08-05
        • 2017-11-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多