Wayaer / fl_pip

flutter picture-in-picture plugin for ios and android
MIT License
27 stars 14 forks source link

How to enable the PiP mode if home button get clicked? #2

Closed TinhHuynh closed 1 year ago

TinhHuynh commented 1 year ago

Hi, thanks for the awesome library. I have a question: How to enable the PiP mode if the home button gets clicked?

Wayaer commented 1 year ago

Call FlPiP().enable() to enable PiP,

class _State extends State<T> with WidgetsBindingObserver{

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    switch (state) {
      case AppLifecycleState.inactive:
        break;
      case AppLifecycleState.paused: 
     /// app enters background
       FlPiP().enable()
        break;
      case AppLifecycleState.resumed: 
        break;
      case AppLifecycleState.detached:
        break;
    }
  }
  @override
  void dispose() {
    super.dispose();
    WidgetsBinding.instance.removeObserver(this);
  }
}
TinhHuynh commented 1 year ago

Thanks <3