Skip to content

App Crashes with "No StoreProvider<Store<State>> found." on launch. #46

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
tluckett77 opened this issue May 9, 2018 · 6 comments
Closed

Comments

@tluckett77
Copy link

tluckett77 commented May 9, 2018

I can't seem to get this working. My app crashes right at boot since attempting to upgrade to the latest flutter redux. Below is the currently set up that I am working with.

dependencies:
  # Redux
    redux: "^3.0.0"
    flutter_redux: "^0.5.0"
Flutter 0.3.2 • channel beta • https://github.com/flutter/flutter.git
Framework • revision 44b7e7d3f4 (3 weeks ago) • 2018-04-20 01:02:44 -0700
Engine • revision 09d05a3891
Tools • Dart 2.0.0-dev.48.0.flutter-fe606f890b

The Code Which is Crashing:

final store = new Store<PrimeAppStateModel>(
    appReducer,
    initialState: new PrimeAppStateModel().initState(), /* initState Returns instance of PrimeAppStateModel */
    middleware: [loggingMiddleware]
  );

  runApp(
    new StoreProvider<PrimeAppStateModel>(
      store: store,
      child: new MaterialApp(
        debugShowCheckedModeBanner: _isDebugBannerOn,
        localizationsDelegates: [
          const HLocalizationsDelegate(),
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
        ],
        supportedLocales: AppSettings.supportedLocales,
        onGenerateTitle: (BuildContext context) => HLocalizations.of(context).appName,
        color: HColors.canvas,
        theme: HTheme.baseTheme(),
        home: new AppLaunch()
      )
    )
  );

class AppLaunch extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
   return new Scaffold(
      backgroundColor: HColors.purple,
      body: new StoreConnector<PrimeAppStateModel, Store<PrimeAppStateModel>>(
        converter: (store) => store,
        onInit: (store){ 
            AppEntryModel modalModel = new AppEntryModel.set(
                HLocalizations.of(context),
                modalMode: ModalMode.login
          );
          store.dispatch(new AppEntryInitAction(modalModel));
        }
        builder: (BuildContext build, store) => new Container()

The Error On Build Completion:

I/flutter (20772): :: ACTION LOG :: 2018-05-09 00:35:43.225096: Instance of 'AppEntryInitAction'
I/flutter (20772): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (20772): The following StoreProviderError was thrown building StoreConnector<Store<PrimeAppStateModel>, () =>
I/flutter (20772): void>(dirty):
I/flutter (20772): Error: No StoreProvider<Store<PrimeAppStateModel>> found. To fix, please try:
I/flutter (20772):           
I/flutter (20772):   * Using Dart 2 (required) by using the --preview-dart-2 flag
I/flutter (20772):   * Wrapping your MaterialApp with the StoreProvider<State>, rather than an individual Route
I/flutter (20772):   * Providing full type information to your Store<State>, StoreProvider<State> and
I/flutter (20772):     StoreConnector<State, ViewModel>

I have checked to make sure that the app is running in Dart 2.0, and it is enabled in Android Studio -> Preferences -> Languages & Frameworks -> Flutter

The launch screen is displayed and then the AppLaunch's StoreConnector runs, since I get a log notice from my logging middleware that store.dispatch(new AppEntryInitAction(modalModel)); action has started. At that point the App Crashes.

I've tried some time trying to isolate where this is happening, and can't seem to pin-point it.

@brianegan
Copy link
Owner

Hey hey -- sorry about the trouble! Looks like what you've pasted makes sense. Could you please also post your import statements? Dart is a bit weird about how it imports files, and if you import the PrimeAppStateModel differently in different files, it can lead to errors like the ones you've posted here.

Thanks!

@tluckett77
Copy link
Author

tluckett77 commented May 9, 2018

No worries, Flutter is still in such flux that these things tend to happen.

The main.dart function looks as follows:

import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';
import 'package:h_app/app_settings.dart';
import 'package:h_app/models/app_state/primary_app_state_model.dart';
import 'package:h_app/views/section_s/s1_welcome.dart';
import 'package:h_app/h_localization.dart';
import 'package:h_app/hTheme/colors.dart';
import 'package:h_app/reducers/app_reducer_core.dart';
import 'package:h_app/middleware/mw_initializers.dart';

s1_welcome.dart which contains the AppLaunch class looks as follows:

import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show SystemChannels;
import 'package:flutter/widgets.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:h_app/actions/sectionS_actions.dart';
import 'package:h_app/models/app_state/primary_app_state_model.dart';
import 'package:h_app/customWidgets/buttons.dart';
import 'package:h_app/hTheme/colors.dart';
import 'package:h_app/main.dart' show getFirebaseAnalytics;
import 'package:h_app/models/section_s/s_pm_entry_modal.dart';
import 'package:h_app/h_localization.dart';
import 'package:h_app/hTheme/app_graphics.dart';
import 'package:h_app/hTheme/icons.dart';
import 'package:h_app/views/section_s/s1:m1_login_modal.dart';
import 'package:redux/redux.dart';

Maybe this is is helpful. I found it in the android IDE internal Error Log

Caused by: java.lang.RuntimeException: Error while applying io.flutter.console.FlutterConsoleFilter@238d2b2c to 'I/flutter ( 5488): #0      StoreProvider.of (package:flutter_redux/flutter_redux.dart:29:27)
'
	at com.intellij.execution.filters.CompositeFilter.applyFilter(CompositeFilter.java:81)
	at com.intellij.execution.impl.AsyncFilterRunner$HighlighterJob.analyzeLine(AsyncFilterRunner.java:214)
	at com.intellij.execution.impl.AsyncFilterRunner$HighlighterJob.analyzeNextLine(AsyncFilterRunner.java:199)
	at com.intellij.execution.impl.AsyncFilterRunner.runTasks(AsyncFilterRunner.java:151)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1130)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runInReadActionWithWriteActionPriority$0(ProgressIndicatorUtils.java:85)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runWithWriteActionPriority$2(ProgressIndicatorUtils.java:141)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:157)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:543)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:488)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:94)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:144)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runWithWriteActionPriority(ProgressIndicatorUtils.java:139)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(ProgressIndicatorUtils.java:85)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(ProgressIndicatorUtils.java:106)
	at com.intellij.execution.impl.AsyncFilterRunner.runFiltersInBackground(AsyncFilterRunner.java:69)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at com.intellij.util.concurrency.BoundedTaskExecutor$2.run(BoundedTaskExecutor.java:212)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.substring(String.java:1967)
	at io.flutter.console.FlutterConsoleFilter.applyFilter(FlutterConsoleFilter.java:124)
	at com.intellij.execution.filters.CompositeFilter.applyFilter(CompositeFilter.java:75)
	... 21 more

@tluckett77
Copy link
Author

I have been able to get the app to finally load without crashing. Seems the crash was related to an issue caused by incompatible google library version combinations in my pubspec.yaml. So the good new is, the crashing was unrelated to flutter_redux. However, the same problem persists with the same error Messages.

05-09 20:58:16.288 7664-7731/com.networks.haillio I/flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
05-09 20:58:16.294 7664-7731/com.networks.haillio I/flutter: The following StoreProviderError was thrown building StoreConnector<Store<PrimeAppStateModel>, () =>
05-09 20:58:16.295 7664-7731/com.networks.haillio I/flutter: void>(dirty):
    Error: No StoreProvider<Store<PrimeAppStateModel>> found. To fix, please try:

So for now we can rule out the flutter_redux package as being the cause of crashing.

@brianegan
Copy link
Owner

Ah, that's interesting -- but yah, still seems like you're hitting a snag with flutter_redux, as it seems like it's unable to find the Store in the Widget Tree. Is your code open source by chance? I'd be happy to dive in and take a look if so.

@tluckett77
Copy link
Author

tluckett77 commented May 15, 2018

Finally found the issue whew This problem was not caused by the redux package, it was directly related to strict types in Dart 2. I had a deeply nested widget in the widget tree that did not have StoreConnector<Store<PrimeAppStateModel>> it was just in my code as StoreConnector<Store>.

I will close this out as it is not an issue, but an error on my part. When you have a chance, it may be noteworthy in the documentation to highlight that the StoreConnector and StoreBuilders must be typed to match the top level StoreProvider. Any deviation causes the problem that I was having.

Thanks for the good work you're doing!

@brianegan
Copy link
Owner

Thanks @tluckett77! Dang, sorry to hear it took you a while to find this one.

I think I definitely need to add an FAQ for this issue as well -- I tried to put that information in the error message that you pasted, but it looks like that wasn't helpful.

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