【发布时间】:2019-12-16 08:50:02
【问题描述】:
所以,我正在尝试创建一个聊天应用程序并尝试让用户参与进来,但在阅读了网络上的大量文章后,我仍然不明白如何让它发挥作用。所以我正在尝试另一个方法,我怎样才能制作一个检查整个应用程序的观察者?
例如,现在我有一个用于在与某人聊天时告诉 Firebase Firestore(设置 ID 以使 Cloud Functions 不会通知新消息),并且我想用它来告诉 Firestore 当我与某人聊天时在线/离线。可能吗?谢谢。
我尝试创建一个有状态的 BaseScreen with WidgetsBindingObserver,但没有成功。
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.inactive:
case AppLifecycleState.paused:
case AppLifecycleState.suspending:
//offline or whatever
break;
case AppLifecycleState.resumed:
//active
break;
}
}
【问题讨论】:
标签: android firebase flutter google-cloud-firestore google-cloud-functions