Best way to reuse a VideoPlayerController after disposing it

83 Views Asked by At

I'm using a scrollable widget like ListView.builder to display a list of VideoPlayer widgets. However, when scrolling, the VideoPlayerController widgets stop initializing after a scrolling a few.

My attempt to fix this issue was to dispose of every VideoPlayerController behind the current widget that's being displayed. That fixed this but however, I need a way to re-display the previous VideoPlayer widget if a user decides to scroll back but it's already disposed hence getting this error:

FlutterError (A VideoPlayerController was used after being disposed.
Once you have called dispose() on a VideoPlayerController, it can no longer be used.)

What's the best way I could achieve this?

I could think of this solution:

  • Recreate a new VideoPlayerController and re-initialize that controller

but is there any other better way? Thanks in advance

1

There are 1 best solutions below

0
Yakup Okumuş On

Make your video player part stateful, then initialize and dispose your controller in it.