You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for providing a wonderfully useful class to a Flutter novice like me - it's very much appreciated. I'm not sure whether this is an issue with the class itself or (far more likely) my understanding of how inherited widgets work.
I'm building a medical quiz app, and require the [UserBloc] object to be accessible anywhere in the app, to allow it to receive events regarding the user's progress through the various levels and so forth. To do this, I've decided to wrap my [MaterialApp] in your [BlocProvider] that (should) provide the [UserBloc] wherever I need it. However, I'm getting some "Unable to find BloC of type _BlocProvider" in some unexpected places.
In particular, note that on line 18 of CareerPage.dart I can access the BlocProvider.of(context).stateStream without throwing any errors. However, in line 23 of the build method of CareerPath.dart, when that runs I get the exception:
flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building CareerPath(dirty, state: _CareerPathState#66b7b):
flutter: Unable to find BLoC of type _BlocProvider.
flutter: Context provided: CareerPath(dirty, state: _CareerPathState#66b7b)
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 _BlocProvider.of (package:generic_bloc_provider/src/bloc_provider.dart:62:7)
flutter: #1 BlocProvider.of (package:generic_bloc_provider/src/bloc_provider.dart:20:21)
flutter: #2 _CareerPathState.build (package:dailymedicaltrivia2/ui/CareerPath.dart:23:34)
flutter: #3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4012:27)
flutter: #4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3924:15)
flutter: #5 Element.rebuild (package:flutter/src/widgets/framework.dart:3721:5)
flutter: #6 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3907:5)
flutter: #7 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4053:11)
flutter: #8 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3902:5)
flutter: #9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3084:14)
flutter: #10 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5198:32)
flutter: #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3084:14)
flutter: #12 Element.updateChild (package:flutter/src/widgets/framework.dart:2887:12)
flutter: #13 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3935:16)
flutter: #14 Element.rebuild (package:flutter/src/widgets/framework.dart:3721:5)
flutter: #15 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2340:33)
flutter: #16 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:700:20)
flutter: #17 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:285:5)
flutter: #18 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1016:15)
flutter: #19 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:958:9)
flutter: #20 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:874:5)
flutter: #24 _invoke (dart:ui/hooks.dart:236:10)
flutter: #25 _drawFrame (dart:ui/hooks.dart:194:3)
flutter: (elided 3 frames from package dart:async)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
So how can BlocProvider.of<UserBloc>(context) be the source of the [StreamBuilder] on line 18 of CareerPage.dart, be valid on line 38, yet be gone by the time I try to build the CareerPath on line 45?
EDIT: I've realised it looks like GitHub does not supply line numbers so I've tagged the relevant lines with the form <Line18>, <Line38>, <Line45> if you want to find the relevant parts quickly.
Please let me know if you require any more information or a simpler example to help you understand the issue I'm having.
Many thanks
The text was updated successfully, but these errors were encountered:
Update: I've managed to resolve this issue myself.
The problem was that in main.dart, I was importing: import 'package:dailymedicaltrivia2/bloc/User/UserBloc.dart';
and in CareerPath.dart I was importing: import 'package:dailymedicaltrivia2/bloc/user/UserBloc.dart';.
Note that they have different capitalisation. This led to a toxic and difficult to debug error in which main.dart was creating a "User/UserBloc.dart", and the [BLocProvider] in CareerPath.dart was looking for a "user/UserBloc.dart". Problem was resolved by changing the capitalisation to be consistent across all files. Leaving this here so that hopefully someone else is saved 10+ hours from this problem.
Hi @joshcase, happy to see that you've been able to solve it and sorry to not have been able to help. I was waiting to have more time to take a look at your issue but you got ahead 😉
Hi Roberto,
Thanks for providing a wonderfully useful class to a Flutter novice like me - it's very much appreciated. I'm not sure whether this is an issue with the class itself or (far more likely) my understanding of how inherited widgets work.
I'm building a medical quiz app, and require the [UserBloc] object to be accessible anywhere in the app, to allow it to receive events regarding the user's progress through the various levels and so forth. To do this, I've decided to wrap my [MaterialApp] in your [BlocProvider] that (should) provide the [UserBloc] wherever I need it. However, I'm getting some "Unable to find BloC of type _BlocProvider" in some unexpected places.
See the following:
main.dart
PrePlayPage.dart
CareerPage.dart
CareerPath.dart
In particular, note that on line 18 of CareerPage.dart I can access the BlocProvider.of(context).stateStream without throwing any errors. However, in line 23 of the build method of CareerPath.dart, when that runs I get the exception:
flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building CareerPath(dirty, state: _CareerPathState#66b7b):
flutter: Unable to find BLoC of type _BlocProvider.
flutter: Context provided: CareerPath(dirty, state: _CareerPathState#66b7b)
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 _BlocProvider.of (package:generic_bloc_provider/src/bloc_provider.dart:62:7)
flutter: #1 BlocProvider.of (package:generic_bloc_provider/src/bloc_provider.dart:20:21)
flutter: #2 _CareerPathState.build (package:dailymedicaltrivia2/ui/CareerPath.dart:23:34)
flutter: #3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4012:27)
flutter: #4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3924:15)
flutter: #5 Element.rebuild (package:flutter/src/widgets/framework.dart:3721:5)
flutter: #6 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3907:5)
flutter: #7 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4053:11)
flutter: #8 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3902:5)
flutter: #9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3084:14)
flutter: #10 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5198:32)
flutter: #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3084:14)
flutter: #12 Element.updateChild (package:flutter/src/widgets/framework.dart:2887:12)
flutter: #13 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3935:16)
flutter: #14 Element.rebuild (package:flutter/src/widgets/framework.dart:3721:5)
flutter: #15 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2340:33)
flutter: #16 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:700:20)
flutter: #17 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:285:5)
flutter: #18 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1016:15)
flutter: #19 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:958:9)
flutter: #20 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:874:5)
flutter: #24 _invoke (dart:ui/hooks.dart:236:10)
flutter: #25 _drawFrame (dart:ui/hooks.dart:194:3)
flutter: (elided 3 frames from package dart:async)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
So how can
BlocProvider.of<UserBloc>(context)
be the source of the [StreamBuilder] on line 18 of CareerPage.dart, be valid on line 38, yet be gone by the time I try to build the CareerPath on line 45?EDIT: I've realised it looks like GitHub does not supply line numbers so I've tagged the relevant lines with the form
<Line18>, <Line38>, <Line45>
if you want to find the relevant parts quickly.Please let me know if you require any more information or a simpler example to help you understand the issue I'm having.
Many thanks
The text was updated successfully, but these errors were encountered: