0

enter image description here

I have inserted the logic for increasing count upon receiving notification in the onMessage of firebase messaging. But the count value increases just once when there is no internet and multiple notifications comes at once. In that case when the app is still in the foreground and after the internet connection is restored the count just increases once.

  • [Please don't post screenshots of text](https://meta.stackoverflow.com/a/285557/354577). They can't be searched or copied, or even consumed by users of adaptive technologies like screen readers. Instead, paste the code as text directly into your question. If you select it and click the `{}` button or Ctrl+K the code block will be indented by four spaces, which will cause it to be rendered as code. – ChrisGPT was on strike Oct 14 '21 at 23:45

1 Answers1

0

You can use a storage manager like shared_preferences to cache your issue.

_incrementCounter() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  int counter = (prefs.getInt('counter') ?? 0) + 1;
  print('Pressed $counter times.');
  await prefs.setInt('counter', counter);
}
m4n0
  • 29,823
  • 27
  • 76
  • 89