Skip to content

Cannot read properties of null (reading 'isAsync') - Flutter Web Release/Profile mode #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ohhfreddypleaseno opened this issue Nov 2, 2021 · 1 comment

Comments

@ohhfreddypleaseno
Copy link

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)

Maybe somebody faced those issues and has solution? Thanks.

@ohhfreddypleaseno
Copy link
Author

ohhfreddypleaseno commented Nov 3, 2021

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 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 {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant