我面临一个问题,在颤动中更改屏幕后未调用 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');
},
以上只是点击抽屉列表项中的一项后调用的代码的一部分。为什么在GameState
dispose 方法中不调用?