@@ -2,33 +2,7 @@ import 'package:chewie/src/chewie_progress_colors.dart';
22import 'package:flutter/material.dart' ;
33import 'package:video_player/video_player.dart' ;
44
5- /// The state of the [ChewieController] .
6- @immutable
7- class ChewieValue {
8- ChewieValue ({
9- this .isFullScreen = false ,
10- });
11-
12- /// True if the video is currently playing fullscreen
13- final bool isFullScreen;
14-
15- ChewieValue copyWith ({
16- VideoPlayerController videoPlayerController,
17- bool isFullScreen,
18- }) {
19- return ChewieValue (
20- isFullScreen: isFullScreen ?? this .isFullScreen,
21- );
22- }
23-
24- @override
25- String toString () {
26- return '$runtimeType ('
27- 'isFullscreen: $isFullScreen , ' ;
28- }
29- }
30-
31- class ChewieController extends ValueNotifier <ChewieValue > {
5+ class ChewieController extends ChangeNotifier {
326 ChewieController ({
337 this .videoPlayerController,
348 this .aspectRatio,
@@ -43,9 +17,8 @@ class ChewieController extends ValueNotifier<ChewieValue> {
4317 this .showControls = true ,
4418 this .allowedScreenSleep = true ,
4519 this .isLive = false ,
46- }) : assert (videoPlayerController != null ,
47- 'You must provide a controller to play a video' ),
48- super (ChewieValue ()) {
20+ }) : assert (videoPlayerController != null ,
21+ 'You must provide a controller to play a video' ) {
4922 _initialize ();
5023 }
5124
@@ -94,7 +67,9 @@ class ChewieController extends ValueNotifier<ChewieValue> {
9467 /// Defines if the controls should be for live stream video
9568 final bool isLive;
9669
97- bool get isFullScreen => value.isFullScreen;
70+ bool _isFullScreen = false ;
71+
72+ bool get isFullScreen => _isFullScreen;
9873
9974 Future _initialize () async {
10075 await videoPlayerController.setLooping (looping);
@@ -117,24 +92,26 @@ class ChewieController extends ValueNotifier<ChewieValue> {
11792
11893 if (fullScreenByDefault) {
11994 videoPlayerController.addListener (() async {
120- if (await videoPlayerController.value.isPlaying &&
121- ! value.isFullScreen) {
95+ if (await videoPlayerController.value.isPlaying && ! _isFullScreen) {
12296 enterFullscreen ();
12397 }
12498 });
12599 }
126100 }
127101
128102 void enterFullscreen () {
129- value = value.copyWith (isFullScreen: true );
103+ _isFullScreen = true ;
104+ notifyListeners ();
130105 }
131106
132107 void exitFullscreen () {
133- value = value.copyWith (isFullScreen: false );
108+ _isFullScreen = false ;
109+ notifyListeners ();
134110 }
135111
136112 void toggleFullscreen () {
137- value = value.copyWith (isFullScreen: ! value.isFullScreen);
113+ _isFullScreen = ! _isFullScreen;
114+ notifyListeners ();
138115 }
139116
140117 void play () {
0 commit comments