小编Jas*_*ott的帖子

firebase_database 在线/离线状态

在使用 firebase 和 flutter-fire firebase_database 插件时,我们如何确定我们的 Flutter 应用是在线还是离线?

这篇博文 ( https://firebase.googleblog.com/2013/06/how-to-build-presence-system.html ) 展示了使用“.info/connected”子在应用上线时获取事件/离线。然而,它似乎只在应用程序启动时触发一次,仅此而已。

我正在使用这个:

void initState() {
    super.initState();

    print('Setting up the connected handler');
    final amOnline = FirebaseDatabase.instance.reference().child('.info/connected');
    _amOnlineSubscription = amOnline.onValue.listen((Event event) {
      print('EVENT has occured');
    });
  }
Run Code Online (Sandbox Code Playgroud)

也许有更好的方法来确定在线/离线状态?我想要做的是在设备离线时避免登录页面。然而,一旦它再次连接到 firebase 就强制登录......

flutter

6
推荐指数
1
解决办法
1239
查看次数

标签 统计

flutter ×1