Skip to content
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

The getter 'store' was called on null #38

Closed
darioielardi opened this issue Apr 16, 2018 · 10 comments
Closed

The getter 'store' was called on null #38

darioielardi opened this issue Apr 16, 2018 · 10 comments

Comments

@darioielardi
Copy link

Hi,

I'm trying to implement redux on my flutter app, versions:

  redux: "^3.0.0"
  flutter_redux: "^0.5.0"

When I run my app the error in the title is thrown.
I followed the Dart 2 migration guide for both the packages.

Flutter: 0.2.8
Dart: 2.0.0

@brianegan
Copy link
Owner

Sorry about that! I need to add one more error case to the error message: How are you importing your files? If you're using relative paths, e.g. import '../store.dart' rather than import package:my_app/store.dart you may run into this issue.

If that's not the case, could you please provide a bit more code, even a repo with the code that's failing? That way I can help debug :)

@darioielardi
Copy link
Author

darioielardi commented Apr 17, 2018

Thanks @brianegan for your answer, but trying to import with absolute path didn't change anything, the error message is still there.
Unfortunately I can't provide the repo, but basically my code looks like:

import 'package:test/modules/store.dart';

  runApp(
    new StoreProvider<AppState>(
      store: store,
      child: new MaterialApp(
        title: 'Test App',
        theme: new ThemeData(
          textTheme: new TextTheme(
            display1: new TextStyle(fontFamily: 'Rubik'),
          )
        ),
        home: new TestApp()
      )
    )
  );

my store:

var store = new Store<AppState>(
  rootReducer,
  initialState: new AppState(
    user: new UserState(null, true),
    connection: new ConnectionState(false)
  ),
  middleware: middlewares
);

and in my TestApp basically there's a StoreConnector that causes the error, nothing happens if I avoid to use that.

    return new StoreConnector<AppState, UserState>(
      converter: (store) => store.state.user,
      builder: (BuildContext ctx, userState) {
        if (userState.currentUser == null) {
          return new Landing(userState.loading);
        }
        return new Dashboard();
      },
    );

The error:

I/flutter (11060): The following NoSuchMethodError was thrown building StoreConnector<AppState, UserState>(dirty):
I/flutter (11060): The getter 'store' was called on null.
I/flutter (11060): Receiver: null
I/flutter (11060): Tried calling: store

@brianegan
Copy link
Owner

Hrm, interesting -- could you please check your pubspec.lock and verify you're on flutter_redux version 0.5.0? Since 0.4.1, if the store is null, it should throw a different error message from this.

Thanks!

@darioielardi
Copy link
Author

Thanks again for your help, looks like I'm on the correct version:

  flutter_redux:
    dependency: "direct main"
    description:
      name: flutter_redux
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.5.0"

@brianegan
Copy link
Owner

brianegan commented Apr 19, 2018

Hrm, this is odd... I can't quite reproduce the issue, and it's a bit baffling that you're getting that particular error message, since the code explicitly does a null-check before accessing the store :(

Does the example app in this repo run for you without issue? Another option: Could you please try accessing the store directly via StoreProvider.of<AppState>(context) in the build method to see if that's failing?

@darioielardi
Copy link
Author

The example in this repo works correctly.
Trying to call StoreProvider.of(context) in the build method an error is thrown but with StoreProvider.of<AppState>(context) everything works.

@darioielardi
Copy link
Author

Now the error is different. My code:

    return new StoreConnector<AppState, UserState>(
      converter: (store) => store.state.user,
      builder: (BuildContext ctx, userState) {
        ...
      }
    );

It throws this error:

The following StoreProviderError was thrown building StoreConnector<AppState, UserState>(dirty):
Error: No StoreProvider<AppState> found. To fix, please try:

  * Using Dart 2 (required) by using the --preview-dart-2 flag
  * Wrapping your MaterialApp with the StoreProvider<State>, rather than an individual Route
  * Providing full type information to your Store<State>, StoreProvider<State> and
     StoreConnector<State, ViewModel>

Which is quite weird because my StoreProvider is implemented like:

final store = new Store<AppState>(...);
...
return new StoreProvider<AppState>(
  store: store,
  child: new MaterialApp(...)
);

@brianegan
Copy link
Owner

brianegan commented Apr 24, 2018

Hey @darioielardi -- Ok, making progress! That's definitely the error you should be seeing. However, this is an odd one since it seems as though you're following the directions.

The last thing I could think of: Does your AppState live in it's own file, or does it live in the main.dart where you declare the StoreProvider<AppState>? If it lives side-by-side with your StoreProvider<AppState>, this can cause odd errors with Dart.

Please see this issue for more details and an open-source example that's been fixed: #35

@darioielardi
Copy link
Author

In some way I solved the problem.

Basically I created another project, and copy-pasting the code the same error was thrown, but when I tried to rewrite it (without referring at the previous version) everything worked. Then I figured out that it depended on the imports, as @brianegan told me some comments above, so using only relatives imports everything was okay, so I tried to replace every absolute import on the previous project with a relative one, but it didn't work, probably due to some other messy stuff. Now I'm working on the second project.

@brianegan
Copy link
Owner

Ok, voodoo magic. I'm at IO and will see if I can chat with a Dart team member about this issue :) A lot of peeps suffer from it!

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

2 participants