使用 Agora SDK 进行视频通话时的 Flutter Notification

Flutter Notification while in Video Call using Agora SDK

我是 Flutter 新手。我正在使用视频 SDK 开发应用程序。我想知道的是,当您进行视频通话并按下主页按钮时,该应用程序在后台运行,那时我想将通知显示为 "you are in a video call" 并且在单击时需要打开该应用程序。谁能帮帮我

要获取应用程序的状态以及该应用程序是 运行 在后台、处于非活动状态还是已完全销毁,我们使用 WidgetsBindingObserverand 并将其与 AppLifecycleState 结合使用。

因此您的代码将如下所示:

class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver{
  @override
  void initState() { 
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }
  @override
  void dispose() { 
    WidgetsBinding.instance.addObserver(this);
    super.dispose();
  }
  @override
  void didChangeAppLifecycleState(AppLifecycleState state){
    super.didChangeAppLifecycleState(state);
    switch (state) {
      case AppLifecycleState.paused:
        //App is running in the background
        break; 
      case AppLifecycleState.resumed:
        //App is being used again 
        break;
      case AppLifecycleState.inactive:
        //App is in foreground but inactive
        break;
      case AppLifecycleState.detached:
        //App view has been destroyed
        break;
    }
  }