Giter Site home page Giter Site logo

Comments (10)

darioielardi avatar darioielardi commented on July 19, 2024 2

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.

from flutter_redux.

brianegan avatar brianegan commented on July 19, 2024 2

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!

from flutter_redux.

brianegan avatar brianegan commented on July 19, 2024

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 :)

from flutter_redux.

darioielardi avatar darioielardi commented on July 19, 2024

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

from flutter_redux.

brianegan avatar brianegan commented on July 19, 2024

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!

from flutter_redux.

darioielardi avatar darioielardi commented on July 19, 2024

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"

from flutter_redux.

brianegan avatar brianegan commented on July 19, 2024

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?

from flutter_redux.

darioielardi avatar darioielardi commented on July 19, 2024

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.

from flutter_redux.

darioielardi avatar darioielardi commented on July 19, 2024

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(...)
);

from flutter_redux.

brianegan avatar brianegan commented on July 19, 2024

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

from flutter_redux.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.