4

我面临一个问题,在颤动中更改屏幕后未调用 dispose 方法。首先是源代码。

class Game extends StatefulWidget {

  Game({Key key, this.title}) : super(key: key);

  final String title;
  @override
  _GameState createState() => new _GameState();
}

class _GameState extends State<Game>  with SingleTickerProviderStateMixin {

  final CrosswordController myController = CrosswordController();

  var chewieController = null;
  var videoPlayerController = null;


  Widget makeVideoStreaming(){
    videoPlayerController = VideoPlayerController.network("https://somelink.com");
    chewieController = ChewieController(//paramtere here
    );
  }

  @override
  void initState() {
    super.initState();
   this.makeVideoStreaming();
    _controller =  AnimationController(vsync: this, duration: Duration(minutes: gameTime));
  }

  @override
  void dispose(){
    print('DISPOSE CALLED- GAME---');
    videoPlayerController.dispose();
    chewieController.dispose();
    _controller.dispose();
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: _onBackPressed,
      child:  Scaffold(
        key: _scaffoldKey,
        drawer: NavigationDrawer(),
        resizeToAvoidBottomPadding: false,

        body://body here
      ),
    );
  }
}

NavigationDrawer()我更改为类似这样的一些不同路线。

 onTap: () {
   Navigator.pop(context); Navigator.pushNamed(context, '/edit_profile');
 },

以上只是点击抽屉列表项中的一项后调用的代码的一部分。为什么在GameStatedispose 方法中不调用?

4

2 回答 2

12

从堆栈中删除屏幕时调用的 Dispose 方法意味着当您使用navigator.pop()pushReplacement 时

于 2020-05-05T11:27:07.853 回答
1

这是一个已知的错误:https
://github.com/flutter/flutter/issues/40940 即使您从官方文档中复制示例,它也不会被调用:https ://flutter.dev/docs/cookbook/networking/web -sockets#complete-example
我已经启动了一个flutter-dev线程来确定是否应该使用其他东西:https ://groups.google.com/g/flutter-dev/c/-0QZFGO0p-g/ m/bictyZWCCAAJ

于 2021-05-28T21:29:23.830 回答