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

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 * #99

Closed
Abgaryan opened this issue Jan 23, 2019 · 12 comments

Comments

@Abgaryan
Copy link

Time to time getting Crashlytcis report like this:

Non-fatal Exception: package:flutter_redux/flutter_redux.dart 29 in StoreProvider.of 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> If none of these solutions work, please file a bug at: https://github.com/brianegan/flutter_redux/issues/new

Note: In the app regulary using the Redux and it works fine.

Here is the app snippet:

import 'dart:async';
import 'package:driveddy/app/app_state.dart';
import 'package:driveddy/app/app_state_reducer.dart';
import 'package:driveddy/app/middleware.dart';
import 'package:driveddy/app/routes.dart';
import 'package:driveddy/app/theme.dart';
import 'package:driveddy/localization/fallback_cupertino_localization_delegate.dart';
import 'package:driveddy/values/keys.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_badger/flutter_app_badger.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';

class App extends StatefulWidget {
  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App>  {
  
  static Store<AppState> store = new Store<AppState>(
    appStateReducer,
    initialState: new AppState.loading(),
    middleware: createMiddleware(),
  );

  @override
  Widget build(BuildContext context) {
    return new StoreProvider<AppState>(
      store: store,
      child: new StoreConnector<AppState, _ViewModel>(
        converter: _ViewModel.fromStore,
        distinct: true,
        builder: (context, vm) {
          return new MaterialApp(
            localeResolutionCallback: (deviceLocale, supportedLocales) {
              return deviceLocale;
            },
            localizationsDelegates: [
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
              const FallbackCupertinoLocalizationsDelegate(),
            ],
            showPerformanceOverlay: vm.isDebug,
            navigatorKey: Keys.navigator,
            theme: AppTheme.theme,
            initialRoute: Routes.initialRoute,
            routes: Routes.routes(context),
          );
        },
      ),
    );
  }
}

This is the screen where the issue is happening:

@override
 Widget build(BuildContext context) {
   _setIsDisposable(context: context, isDisposable: false);
     return  new Text(
                   "some text",
                   textAlign: TextAlign.center,
                   maxLines: 4,
                   style: new TextStyle(fontSize: 16.0, height: 1.25, color: AppTheme.gray7),
                 );
 }

 void _setIsDisposable({@required BuildContext context, @required bool isDisposable}) {
   StoreProvider.of<AppState>(context).dispatch(new SetIsSignUpStackDisposableAction(isDisposable: isDisposable));
 }

Doctor summary (to see all details, run flutter doctor -v):

[✓] Flutter (Channel beta, v1.0.0, on Mac OS X 10.13.6 17G65, locale en-DE)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.3)
[!] VS Code (version 1.30.2)
[✓] Connected device (1 available)
@brianegan
Copy link
Owner

Hey @Abgaryan :) Sorry I missed this one :/

Hrm, that's super odd. Overall, the code looks correct. Therefore, the only thing I could think of: Somehow the context that you're using is not a context that includes the Store. Is that possible in any way?

@Abgaryan
Copy link
Author

Hello @brianegan,
no it is not possible as you can see the StoreProvider is in the root of the widget tree.The context where the error happnes is in the same widget tree.

@brianegan
Copy link
Owner

Yah, that's what I noticed as well. Hrm, this is a really funny one :/ All flutter_redux is doing under the hood is looking for the proper StoreProvider using a standard InheritedWidget. Therefore, the reason this is failing is a bit hard to see without being able to look at a bit more code.

Do you happen to have any code you can share to reproduce the error, or are you able to reproduce the issue locally and set some breakpoints / do some manual calls? Thanks!

@Abgaryan
Copy link
Author

Unfortunately, I can't reproduce the error, I am getting the error logs via Crashlyics from the live app.

@brianegan
Copy link
Owner

Dang, that's a real bummer :/ In that case, the best thing I could think of is to add more logging in that method. For example, could you wrap the dispatch call in a try / catch block. If an exception occurs, you could try sending up additional information such as the context.

I'm wondering if there's just some weird way a user is getting to that Widget (maybe from a push notification or some other mechanism) that does not setup the correct context?

@Abgaryan
Copy link
Author

I will add exception to the error log and will let you know how it goes.
Regarding Navigation I am doing like this


 Navigator.of(context).push(new MaterialPageRoute<void>(
      builder: (BuildContext context) {
        return pushWidget;
      },
    ));

from other Widget which is in under the StoreProvider in Widget tree .

@brianegan
Copy link
Owner

Thanks!

And Dang -- again, I really can't see anything wrong in that code snippet -- it's an odd bug for sure.

Please definitely let me know if you discover anything from the additional logs and I'd be happy to help out in any way I can!

@brianegan
Copy link
Owner

Hey @Abgaryan -- did you all happen to have any luck tracking this down?

@Abgaryan
Copy link
Author

Hello @brianegan didn't get any crash report with context yet

@brianegan
Copy link
Owner

No worries -- just wanted to check in and see if I could help at all! Always feel free to ping me if this is still coming up and if ya find the cause.

@Abgaryan
Copy link
Author

Abgaryan commented Apr 4, 2019

Hello, @brianegan is it the right approach to dispatch action in dispose()?

 @override
  void dispose() {
    StoreProvider.of<AppState>(context).dispatch(ClearStoreAction());
    super.dispose();
  }

@brianegan
Copy link
Owner

brianegan commented Nov 6, 2019

Oh my -- I missed this one! Generally, you cannot access the store in a dispose method directly since it is using a context that is being torn down. You can instead use the onDipose callback provided by the StoreConnector widget. It can do this in a safe way!

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