导航栏抖动时暂停视频播放器

时间:2020-10-22 06:13:00

标签: flutter lifecycle

我正在制作Tiktok克隆应用

我正在使用IndexedStack来实现这一点。

一切都很好,但是有一个问题

我不知道如何暂停

这是HomeScreen()

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) async {
    print('didChangeAppLifecycleState CALLED ✅');
    if (state != AppLifecycleState.resumed) {
      _videoListController.currentPlayer.pause();
    }
  }

这是navigationBar代码

  @override
  Widget build(BuildContext context) {

    _widgetOptions = <Widget>[
      HomeScreen(), // Video is here ✅
      SearchScreen(),
      ProductScreen(),
      ProfileScreen(),
    ];

    return Scaffold(
      body: IndexedStack(index: _selectedIndex, children: _widgetOptions),
      bottomNavigationBar: Container(
        decoration: BoxDecoration(color: Colors.white, boxShadow: [
          BoxShadow(
            blurRadius: 20,
            color: Colors.black.withOpacity(.1),
          ),
        ]),

        ...

在HomeScreen()中 更改导航索引时未调用didChangeAppLifecycleState 因此,玩家不会自动停止

我该如何解决??

0 个答案:

没有答案