Can't run flutter project in release or profile. In Debug it runs normally without any issue but in other cases I'm getting these error in 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)
My thoughts are that it is related to get_it but can't find any related issues...
Maybe somebody faced those issues and has solution? Thanks.
CodePudding user response:
In some reason in release / profile web build when using get_it injectable bloc (as singleton) and bloc declared as simple class in GetIt method call (code snippet below) type T comes as Object, not as your expected type. GetIt tried to find this Object type in scope of registered types and (How unexpectedly!) does not find it and returns null. Null doesn`t expected and causes an error.
The problem causes only with singleton / lazySingleton. With injectable all seems good.
@override
T call<T extends Object>({
String? instanceName,
dynamic param1,
dynamic param2,
}) {
return get<T>(instanceName: instanceName, param1: param1, param2: param2);
}
So for me, the solution was to change from:
@singleton
class ExampleCubit extends Cubit<ExampleState> {}
to:
abstract class ExampleCubit extends Cubit<ExampleState> {}
@Singleton(as: ExampleCubit)
class ExampleCubitImpl extends ExampleCubit {}