Hi all,
I'm using an InheritedWidget to implement dependency injection in my app. I have a root-level InheritedWidget that holds the dependencies I want to inject throughout.
I'm attempting to access the InheritedWidget's data from a Provider, but I get the following error:
-----
Bad state: Tried to read a provider that threw during the creation of its value.
The exception occurred during the creation of type AuthProvider.
-----
Here is the bit of troublesome code:
-----
class App extends StatelessWidget {
final Environment _environment;
App(this._environment);
@override
Widget build(BuildContext context) {
return InjectorWidget(. // This is my InheritedWidget!
environment: _environment,
child: MultiProvider(
providers: [
ChangeNotifierProvider(
create: (ctx) => AuthProvider(ctx),
), ...
],
child: ...
),
);
}
}
-----
The problem comes from passing the build context into the provider constructor and then attempting to use it to get access to the InheritedWidget. Is this approach even possible? Or am I missing something?
Thanks!
- Matt