Browse Source

Shorten API by adding getters

Ben Hagen 6 years ago
parent
commit
79abb082af

+ 5 - 0
lib/src/chewie_controller.dart

@@ -97,6 +97,11 @@ class ChewieController extends ValueNotifier<ChewieValue> {
   /// Defines if the controls should be for live stream video
   final bool isLive;
 
+  bool get isFullScreen => value.isFullScreen;
+
+  VideoPlayerController get videoPlayerController =>
+      value.videoPlayerController;
+
   Future _initialize() async {
     await value.videoPlayerController.setLooping(looping);
 

+ 1 - 1
lib/src/chewie_player.dart

@@ -43,7 +43,7 @@ class ChewieState extends State<Chewie> {
   }
 
   void listener() async {
-    if (widget.controller.value.isFullScreen && !_isFullScreen) {
+    if (widget.controller.isFullScreen && !_isFullScreen) {
       _isFullScreen = true;
       await _pushFullScreenWidget(context);
     } else if (_isFullScreen) {

+ 3 - 3
lib/src/cupertino_controls.dart

@@ -43,7 +43,7 @@ class _CupertinoControlsState extends State<CupertinoControls> {
     final backgroundColor = widget.backgroundColor;
     final iconColor = widget.iconColor;
     chewieController = ChewieControllerProvider.of(context);
-    controller = chewieController.value.videoPlayerController;
+    controller = chewieController.videoPlayerController;
     final orientation = MediaQuery.of(context).orientation;
     final barHeight = orientation == Orientation.portrait ? 30.0 : 47.0;
     final buttonPadding = orientation == Orientation.portrait ? 16.0 : 24.0;
@@ -73,7 +73,7 @@ class _CupertinoControlsState extends State<CupertinoControls> {
   @override
   void didChangeDependencies() {
     chewieController = ChewieControllerProvider.of(context);
-    controller = chewieController.value.videoPlayerController;
+    controller = chewieController.videoPlayerController;
 
     _dispose();
     _initialize();
@@ -170,7 +170,7 @@ class _CupertinoControlsState extends State<CupertinoControls> {
               ),
               child: Center(
                 child: Icon(
-                  chewieController.value.isFullScreen
+                  chewieController.isFullScreen
                       ? OpenIconicIcons.fullscreenExit
                       : OpenIconicIcons.fullscreenEnter,
                   color: iconColor,

+ 2 - 2
lib/src/material_controls.dart

@@ -66,7 +66,7 @@ class _MaterialControlsState extends State<MaterialControls> {
   @override
   void didChangeDependencies() {
     chewieController = ChewieControllerProvider.of(context);
-    controller = chewieController.value.videoPlayerController;
+    controller = chewieController.videoPlayerController;
 
     _dispose();
     _initialize();
@@ -115,7 +115,7 @@ class _MaterialControlsState extends State<MaterialControls> {
           ),
           child: Center(
             child: Icon(
-              chewieController.value.isFullScreen
+              chewieController.isFullScreen
                   ? Icons.fullscreen_exit
                   : Icons.fullscreen,
             ),

+ 2 - 2
lib/src/player_with_controls.dart

@@ -35,12 +35,12 @@ class PlayerWithControls extends StatelessWidget {
           chewieController.placeholder ?? Container(),
           Center(
             child: Hero(
-              tag: chewieController.value.videoPlayerController,
+              tag: chewieController.videoPlayerController,
               child: AspectRatio(
                 aspectRatio: chewieController.aspectRatio ??
                     _calculateAspectRatio(context),
                 child:
-                    VideoPlayer(chewieController.value.videoPlayerController),
+                    VideoPlayer(chewieController.videoPlayerController),
               ),
             ),
           ),