Parcourir la source

remove _onPlay listener from the controller when the widget is disposed and avoid disposing resource that I'm not the owenr of it (#27)

zshema il y a 7 ans
Parent
commit
5bd3f2c54c
2 fichiers modifiés avec 6 ajouts et 6 suppressions
  1. 0 6
      lib/src/chewie_player.dart
  2. 6 0
      lib/src/player_with_controls.dart

+ 0 - 6
lib/src/chewie_player.dart

@@ -146,12 +146,6 @@ class _ChewiePlayerState extends State<Chewie> {
     }
   }
 
-  @override
-  void dispose() {
-    _controller.dispose();
-    super.dispose();
-  }
-
   Future<dynamic> _pushFullScreenWidget(BuildContext context) async {
     final isAndroid = Theme.of(context).platform == TargetPlatform.android;
     final TransitionRoute<Null> route = new PageRouteBuilder<Null>(

+ 6 - 0
lib/src/player_with_controls.dart

@@ -126,6 +126,12 @@ class _VideoPlayerWithControlsState extends State<PlayerWithControls> {
     }
   }
 
+  @override
+  dispose(){
+    widget.controller.removeListener(_onPlay);
+    super.dispose();
+  }
+
   void _onPlay() {
     if (widget.controller.value.isPlaying) {
       setState(() {