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
Hello everyone, I have a problem with the library. I created an abstract class to handle connectivity across multiple pages in the same way. But I'm getting the error:
`════════ Exception caught by widgets library ═══════════════════════════════════
The following ProviderNotFoundException was thrown building StreamBuilder(state: _StreamBuilderBaseState<ConnectivityResult, AsyncSnapshot>#ab4f1):
Error: Could not find the correct Provider<StateStreamable<Object?>> above this BlocBuilder<StateStreamable<Object?>, Object?> Widget
This happens because you used a BuildContext that does not include the provider
of your choice. There are a few common scenarios:
You added a new provider in your main.dart and performed a hot-reload.
To fix, perform a hot-restart.
The provider you are trying to read is in a different route.
Providers are "scoped". So if you insert of provider inside a route, then
other routes will not be able to access that provider.
You used a BuildContext that is an ancestor of the provider you are trying to read.
Make sure that BlocBuilder<StateStreamable<Object?>, Object?> is under your MultiProvider/Provider<StateStreamable<Object?>>.
This usually happens when you are creating a provider and trying to read it immediately.
For example, instead of:
Widget build(BuildContext context) {
return Provider<Example>(
create: (_) => Example(),
// Will throw a ProviderNotFoundError, because `context` is associated
// to the widget that is the parent of `Provider<Example>`
child: Text(context.watch<Example>().toString()),
);
}
consider using builder like so:
Widget build(BuildContext context) {
return Provider<Example>(
create: (_) => Example(),
// we use `builder` to obtain a new `BuildContext` that has access to the provider
builder: (context, child) {
// No longer throws
return Text(context.watch<Example>().toString());
}
);
}
Hello everyone, I have a problem with the library. I created an abstract class to handle connectivity across multiple pages in the same way. But I'm getting the error:
`════════ Exception caught by widgets library ═══════════════════════════════════
The following ProviderNotFoundException was thrown building StreamBuilder(state: _StreamBuilderBaseState<ConnectivityResult, AsyncSnapshot>#ab4f1):
Error: Could not find the correct Provider<StateStreamable<Object?>> above this BlocBuilder<StateStreamable<Object?>, Object?> Widget
This happens because you used a
BuildContext
that does not include the providerof your choice. There are a few common scenarios:
You added a new provider in your
main.dart
and performed a hot-reload.To fix, perform a hot-restart.
The provider you are trying to read is in a different route.
Providers are "scoped". So if you insert of provider inside a route, then
other routes will not be able to access that provider.
You used a
BuildContext
that is an ancestor of the provider you are trying to read.Make sure that BlocBuilder<StateStreamable<Object?>, Object?> is under your MultiProvider/Provider<StateStreamable<Object?>>.
This usually happens when you are creating a provider and trying to read it immediately.
For example, instead of:
consider using
builder
like so:If none of these solutions work, consider asking for help on StackOverflow:
https://stackoverflow.com/questions/tagged/flutter
The relevant error-causing widget was:
OfflineBuilder OfflineBuilder:file:///C:/..../glufri/lib/widgets/connectivity_widget.dart:9:41
When the exception was thrown, this was the stack:
#0 Provider._inheritedElementOf (package:provider/src/provider.dart:343:7)
#1 Provider.of (package:provider/src/provider.dart:293:30)
#2 ReadContext.read (package:provider/src/provider.dart:649:21)
#3 _BlocBuilderBaseState.initState (package:flutter_bloc/src/bloc_builder.dart:130:36)
#4 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5611:55)
#5 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5456:5)
#6 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4335:16)
#7 Element.updateChild (package:flutter/src/widgets/framework.dart:3840:20)
#8 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#9 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643:11)
#10 Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#11 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2904:19)
#12 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:989:21)
#13 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:448:5)
#14 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1386:15)
#15 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1311:9)
#16 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1169:5)
#17 _invoke (dart:ui/hooks.dart:312:13)
#18 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:399:5)
#19 _drawFrame (dart:ui/hooks.dart:283:31)
`
The text was updated successfully, but these errors were encountered: