Humayun Kabir
Humayun Kabir

Reputation: 611

flutter yoyo player controller

I am using yoyo_player to play live stream video. When I back/pop to the home page, I am getting the following exception:

This widget has been unmounted, so the State no longer has a context (and should be considered defunct)

Exception from console

I can't dispose of yoyo player because it has no controller. Following is my code:

YoYoPlayer(
    aspectRatio: 16 / 9,
    url:
    "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8",
    //"https://stream.mux.com/pYcUEtxsvAyEQBydYkR7dCnBVenRMt7JyuvVno6Y40000.m3u8",
    videoStyle: VideoStyle(
      play : Icon(Icons.play_arrow),
      pause : Icon(Icons.pause),
      fullscreen : Icon(Icons.fullscreen),
    ),
    videoLoadingStyle: VideoLoadingStyle(
      loading: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            CircularProgressIndicator(),
            Text("Loading video"),
          ],
        ),
      ),
    ),
    onfullscreen: (t) {
      if(mounted){
        removeBannerAd();
        setState(() {
          fullscreen = t;
        });
      }

    },
)

How to resolve this exception?

Upvotes: 2

Views: 790

Answers (1)

cshara
cshara

Reputation: 21

I found a solution.

widgetsBinding.addPostFrameCallback((callback) {
      widgetsBinding.addPersistentFrameCallback((callback) {
        if (context == null) return;

Becomes:

widgetsBinding.addPostFrameCallback((callback) {
      widgetsBinding.addPersistentFrameCallback((callback) {
        if (!mounted) return;

Line 151 in video.dart.

Upvotes: 2

Related Questions