I've created a ChangeNotifier and added it to the main.dart providers list like below:
ChangeNotifierProvider<AppState>(
create: (context) => AppState(),
);
and I have a dialog which I wrap in ChangeNotifierProvider.value
to have access to the provider inside dialog, like below:
showDialog(
context: context,
builder: (BuildContext context) {
return ChangeNotifierProvider.value(
value: AppState(),
child: LanguageDialog(),
);
});
});
but the problem is that when I set some data in the provider state inside the dialog it works fine as long as I'm inside the dialog! when I close the dialog the state resets! and I have no idea why this happens. Also I've tried setting some state in another route and the result was that the state's data in that route was not the same as the dialog.
What am I doing wrong here?