OutdatedGuy / cached_video_player_plus

Original video_player plugin with the superpower of caching embedded in Android and iOS.
https://pub.dev/packages/cached_video_player_plus
BSD 3-Clause "New" or "Revised" License
14 stars 7 forks source link

Ensure notifier is not disposed before setValue #36

Closed hantrungkien closed 1 month ago

hantrungkien commented 2 months ago

I have a video list and have a restore position function, but sometime when I scroll ListView I get this issue:

                       A CachedVideoPlayerPlusController was used after being disposed.
Once you have called dispose() on a CachedVideoPlayerPlusContro...
                       #0      ChangeNotifier.debugAssertNotDisposed.<anonymous closure> (package:flutter/src/foundation/change_notifier.dart:179:9)
                       #1      ChangeNotifier.debugAssertNotDisposed (package:flutter/src/foundation/change_notifier.dart:186:6)
                       #2      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:412:27)
                       #3      ValueNotifier.value= (package:flutter/src/foundation/change_notifier.dart:555:5)
                       #4      CachedVideoPlayerPlusController._updatePosition (package:cached_video_player_plus/cached_video_player_plus.dart:862:5)
                       #5      CachedVideoPlayerPlusController.seekTo (package:cached_video_player_plus/cached_video_player_plus.dart:754:5)
                       <asynchronous suspension>
                       #6      _VideoPlayerState._restorePosition (package:*/feed_page.dart:725:7)
                       <asynchronous suspension>
                       #7      _VideoPlayerState.didUpdateWidget.<anonymous closure> (package:*/feed_page.dart:695:35)
                       <asynchronous suspension>
OutdatedGuy commented 1 month ago

@hantrungkien, this'll just ignore functions calls if the controller is disposed. The real issue is that ListView disposes elements that are not in view.

I think you should update your code so that non-visible elements are not garbage collected (disposed).

If you think I missed something, feel free to re-open the PR.