【问题标题】:Can't run flutter web project in Release or Profile (Cannot read properties of null (reading 'isAsync'))无法在 Release 或 Profile 中运行 Flutter Web 项目(无法读取 null 的属性(读取“isAsync”))
【发布时间】:2021-12-17 00:42:37
【问题描述】:

无法在版本或配置文件中运行颤振项目。在 Debug 中它正常运行,没有任何问题,但在其他情况下,我在 Chrome 中遇到这些错误:

zone.dart:1413 
Uncaught TypeError: Cannot read properties of null (reading 'isAsync')
        at _GetItImplementation.$get$1$3$instanceName$param1$param2 (:61215/main.dart.js:164051)
        at _GetItImplementation.call$1$0 (:61215/main.dart.js:164063)
        at _GetItImplementation.call$0 (:61215/main.dart.js:164066)
        at :61215/main.dart.js:45288
        at _wrapJsFunctionForAsync_closure.$protected (:61215/main.dart.js:27970)
        at _wrapJsFunctionForAsync_closure.call$2 (:61215/main.dart.js:69886)
        at _awaitOnObject_closure.call$1 (:61215/main.dart.js:69874)
        at _RootZone.runUnary$2$2 (:61215/main.dart.js:72668)
        at _Future__propagateToListeners_handleValueCallback.call$0 (:61215/main.dart.js:70794)
        at Object._Future__propagateToListeners (:61215/main.dart.js:28268)

我的想法是它与get_it有关,但找不到任何相关问题...

也许有人遇到了这些问题并有解决方案? 谢谢。

【问题讨论】:

    标签: flutter google-chrome web flutter-web


    【解决方案1】:

    出于某种原因,在 release/profile web build 中使用 get_it + injectable + bloc(作为单例)并且 bloc 在 GetIt 方法中声明为简单类 call (下面的代码 sn-p)type T 来自 Object,而不是 您的预期类型。 GetIt 试图在已注册类型的范围内找到此 Object 类型,但(多么出乎意料!)没有找到它并返回 null。 Null 不是预期的,会导致错误。

    该问题仅由单例/惰性单例引起。注射剂一切似乎都很好。

    @override
    T call<T extends Object>({
      String? instanceName,
      dynamic param1,
      dynamic param2,
    }) {
      return get<T>(instanceName: instanceName, param1: param1, param2: param2);
    }
    

    所以对我来说,解决方案是从:

    @singleton
    class ExampleCubit extends Cubit<ExampleState> {}
    

    到:

    abstract class ExampleCubit extends Cubit<ExampleState> {}
    
    @Singleton(as: ExampleCubit)
    class ExampleCubitImpl extends  ExampleCubit {}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-20
      • 1970-01-01
      • 1970-01-01
      • 2018-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-28
      相关资源
      最近更新 更多