Chewie video keeps playing when I leave the page on Flutter

Viewed 1444

I have an app in Flutter that shows videos with Chewie. When I leave the screen where the video is playing, the video continues to play. The Widget that Chewie manages is

    class _crearVideo extends StatefulWidget {

 final video;

  const _crearVideo({this.video});

  @override
  __crearVideoState createState() => __crearVideoState();
}

class __crearVideoState extends State<_crearVideo> {

  VideoPlayerController _videoPlayerController1;
  ChewieController _chewieController;

  @override
  void dispose() {
    _chewieController.pause();
    _chewieController.dispose();
    _videoPlayerController1.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {

    _videoPlayerController1 = VideoPlayerController.network( GlobalConfiguration().getString("rest_server") + "/v1/videoStream/${widget.video.video}");
    _chewieController = ChewieController(
      videoPlayerController: _videoPlayerController1,
      aspectRatio: 16 / 9,
      autoPlay: false,
      looping: false,
      // Try playing around with some of these other options:

      // showControls: false,
      materialProgressColors: ChewieProgressColors(
      //   playedColor: Colors.red,
      //   handleColor: Colors.blue,
      //   backgroundColor: Colors.grey,
         bufferedColor: Colors.orangeAccent,
      // ),
      // placeholder: Container(
      //   color: Colors.grey,
       ),
       autoInitialize: true,
    );

    return Container(
       child: Chewie(
                  controller: _chewieController,
                ));
  }
}

I have a dispose() method that executes but doesn't work.

Any idea?

Thanks and sorry for my English.

1 Answers

In the back button you need to put: Navigator.popAndPushNamed (context, 'Here you can name your route');

Ex:

IconButton(
                  onPressed: (){
                    Navigator.popAndPushNamed(context, '/ConsultantConsulting');
                     },
                  icon: Icon(Icons.arrow_back, color: Colors.white, size: 30,),
                )

To create named routes. what goes between the quotes will be what you will use to call the route. (main.dart):

initialRoute: '/',
routes: {
  '/': (context) => HomePage(),
  '/login': (context) => LoginPage()
Related