Closed tbm98 closed 4 years ago
It's likely that the BuildContext
you passed to submitUpdate
is lower in the tree than the one associated with the provider (that read
uses)
I am declaring RootState
andRestClient
as the top of the tree.
void main() => runApp(
MultiProvider(providers: [
Provider<NavigatorStore>(
create: (_) => NavigatorStore(),
lazy: false,
),
Provider(
create: (_) => SharedPrefs(),
),
Provider(
create: (_) => RestClient.create(),
),
StateNotifierProvider<RootStateNotifier, RootState>(
create: (context) => RootStateNotifier())
], child: MyApp()),
);
then I push to ChangePasswordPage
void _openChangePassword() {
context.push((_) => Provider<ChangePasswordHandler>(
create: (_) => ChangePasswordHandler(),
child: ChangePasswordPage()));
}
and context I passed to submitUpdate
is from ChangePasswordPage
Currently my ChangePasswordHandler
does not inherit any other class, is it a problem?
I have just confirmed this.
read
only works inStateNotifierProvider
, it does not work in Provider
Yes that is expected
Oh. I think the document should warn this.
when I call read<>() it throw Exception
but if I replace by Provider.of(context) it work fine
where am i wrong ?