From c7aa9942a625192b4bed62be4f564a9a3b4f2a62 Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Fri, 17 Jun 2022 01:42:04 +0200 Subject: [PATCH] [video_player] Fix disposed VideoPlayerController throwing an error when calling dispose() again (#5952) --- packages/video_player/video_player/CHANGELOG.md | 3 ++- .../video_player/video_player/lib/video_player.dart | 4 ++++ packages/video_player/video_player/pubspec.yaml | 2 +- .../video_player/test/video_player_test.dart | 11 +++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/video_player/video_player/CHANGELOG.md b/packages/video_player/video_player/CHANGELOG.md index 379909b86e42..2b0ffadaecdf 100644 --- a/packages/video_player/video_player/CHANGELOG.md +++ b/packages/video_player/video_player/CHANGELOG.md @@ -1,6 +1,7 @@ -## NEXT +## 2.4.5 * Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/104231). +* Fixes an exception when a disposed VideoPlayerController is disposed again. ## 2.4.4 diff --git a/packages/video_player/video_player/lib/video_player.dart b/packages/video_player/video_player/lib/video_player.dart index 95bdc07dc86c..96aa881aba39 100644 --- a/packages/video_player/video_player/lib/video_player.dart +++ b/packages/video_player/video_player/lib/video_player.dart @@ -426,6 +426,10 @@ class VideoPlayerController extends ValueNotifier { @override Future dispose() async { + if (_isDisposed) { + return; + } + if (_creatingCompleter != null) { await _creatingCompleter!.future; if (!_isDisposed) { diff --git a/packages/video_player/video_player/pubspec.yaml b/packages/video_player/video_player/pubspec.yaml index 26723992628f..bb0e8a8ec581 100644 --- a/packages/video_player/video_player/pubspec.yaml +++ b/packages/video_player/video_player/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter widgets on Android, iOS, and web. repository: https://github.com/flutter/plugins/tree/main/packages/video_player/video_player issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22 -version: 2.4.4 +version: 2.4.5 environment: sdk: ">=2.14.0 <3.0.0" diff --git a/packages/video_player/video_player/test/video_player_test.dart b/packages/video_player/video_player/test/video_player_test.dart index f4eda111fb92..728e3a29ad99 100644 --- a/packages/video_player/video_player/test/video_player_test.dart +++ b/packages/video_player/video_player/test/video_player_test.dart @@ -373,6 +373,17 @@ void main() { expect(await controller.position, isNull); }); + test('calling dispose() on disposed controller does not throw', () async { + final VideoPlayerController controller = VideoPlayerController.network( + 'https://127.0.0.1', + ); + + await controller.initialize(); + await controller.dispose(); + + expect(() async => await controller.dispose(), returnsNormally); + }); + test('play', () async { final VideoPlayerController controller = VideoPlayerController.network( 'https://127.0.0.1',