This is an ecommerce based app. Im maintaining a map of products viewed by user using provider. When app moves to background, I want to access the provider and make a network call to update the values.
I tried to use provider container
final globalProviderContainer = ProviderContainer();
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.paused) {
final views = globalProviderContainer.read(
viewsCounterNotifierProvider,
);
print(views);
performBackgroundAction();
}
This only returns empty value for the data.
You need to add the following line in
initStateThen do like this:
The other option you can adopt is to use isolate like
and then call this in isolate
To use isolate, use flutter_isolate package