Prechádzať zdrojové kódy

Allow customising controls

More finegraned customisation of exisiting controls to be added later.
Ben Hagen 6 rokov pred
rodič
commit
aeac81200e

+ 1 - 0
lib/chewie.dart

@@ -1,4 +1,5 @@
 library chewie;
 
 export 'src/chewie_player.dart';
+export 'src/chewie_controller.dart';
 export 'src/chewie_progress_colors.dart';

+ 5 - 0
lib/src/chewie_controller.dart

@@ -15,6 +15,7 @@ class ChewieController extends ChangeNotifier {
     this.materialProgressColors,
     this.placeholder,
     this.showControls = true,
+    this.customControls,
     this.allowedScreenSleep = true,
     this.isLive = false,
   }) : assert(videoPlayerController != null,
@@ -40,6 +41,10 @@ class ChewieController extends ChangeNotifier {
   /// Whether or not to show the controls
   final bool showControls;
 
+  /// Defines customised controls. Check [MaterialControls] or
+  /// [CupertinoControls] for reference.
+  final Widget customControls;
+
   /// The Aspect Ratio of the Video. Important to get the correct size of the
   /// video!
   ///

+ 9 - 8
lib/src/player_with_controls.dart

@@ -39,8 +39,7 @@ class PlayerWithControls extends StatelessWidget {
               child: AspectRatio(
                 aspectRatio: chewieController.aspectRatio ??
                     _calculateAspectRatio(context),
-                child:
-                    VideoPlayer(chewieController.videoPlayerController),
+                child: VideoPlayer(chewieController.videoPlayerController),
               ),
             ),
           ),
@@ -55,12 +54,14 @@ class PlayerWithControls extends StatelessWidget {
     ChewieController chewieController,
   ) {
     return chewieController.showControls
-        ? Theme.of(context).platform == TargetPlatform.android
-            ? MaterialControls()
-            : CupertinoControls(
-                backgroundColor: Color.fromRGBO(41, 41, 41, 0.7),
-                iconColor: Color.fromARGB(255, 200, 200, 200),
-              )
+        ? chewieController.customControls != null
+            ? chewieController.customControls
+            : Theme.of(context).platform == TargetPlatform.android
+                ? MaterialControls()
+                : CupertinoControls(
+                    backgroundColor: Color.fromRGBO(41, 41, 41, 0.7),
+                    iconColor: Color.fromARGB(255, 200, 200, 200),
+                  )
         : Container();
   }