Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在firebase消息传递的onMessage中插入了增加计数的逻辑。但是当没有互联网并且同时有多个通知时,计数值只会增加一次。在这种情况下,当应用程序仍在前台并且在互联网连接恢复后,计数只会增加一次。
您可以使用 shared_preferences 之类的存储管理器来缓存您的问题。
_incrementCounter() async { SharedPreferences prefs = await SharedPreferences.getInstance(); int counter = (prefs.getInt('counter') ?? 0) + 1; print('Pressed $counter times.'); await prefs.setInt('counter', counter); }