Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually select desired controls #794

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/chewie.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export 'src/cupertino/cupertino_controls.dart';
export 'src/material/material_controls.dart';
export 'src/material/material_desktop_controls.dart';
export 'src/models/index.dart';
export 'src/helpers/adaptive_controls.dart';
7 changes: 7 additions & 0 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:chewie/src/chewie_progress_colors.dart';
import 'package:chewie/src/helpers/adaptive_controls.dart';
import 'package:chewie/src/models/option_item.dart';
import 'package:chewie/src/models/options_translation.dart';
import 'package:chewie/src/models/subtitle_model.dart';
Expand Down Expand Up @@ -285,6 +286,7 @@ class ChewieController extends ChangeNotifier {
this.progressIndicatorDelay,
this.hideControlsTimer = defaultHideControlsTimer,
this.controlsSafeAreaMinimum = EdgeInsets.zero,
this.controlsType = ControlsType.adaptive,
}) : assert(
playbackSpeeds.every((speed) => speed > 0),
'The playbackSpeeds values must all be greater than 0',
Expand Down Expand Up @@ -332,6 +334,7 @@ class ChewieController extends ChangeNotifier {
List<SystemUiOverlay>? systemOverlaysAfterFullScreen,
List<DeviceOrientation>? deviceOrientationsAfterFullScreen,
Duration? progressIndicatorDelay,
ControlsType? controlsType,
Widget Function(
BuildContext,
Animation<double>,
Expand Down Expand Up @@ -387,6 +390,7 @@ class ChewieController extends ChangeNotifier {
hideControlsTimer: hideControlsTimer ?? this.hideControlsTimer,
progressIndicatorDelay:
progressIndicatorDelay ?? this.progressIndicatorDelay,
controlsType: controlsType ?? this.controlsType
);
}

Expand Down Expand Up @@ -532,6 +536,9 @@ class ChewieController extends ChangeNotifier {
/// Defines a delay in milliseconds between entering buffering state and displaying the loading spinner. Set null (default) to disable it.
final Duration? progressIndicatorDelay;

/// Defines the type of controls (Ex: Material or Cupertino)
final ControlsType controlsType;

/// Adds additional padding to the controls' [SafeArea] as desired.
/// Defaults to [EdgeInsets.zero].
final EdgeInsets controlsSafeAreaMinimum;
Expand Down
19 changes: 19 additions & 0 deletions lib/src/helpers/adaptive_controls.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';

enum ControlsType { cupertino, material, materialDesktop, adaptive }

class AdaptiveControls extends StatelessWidget {
const AdaptiveControls({
Key? key,
required this.controlsType,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider making this nullable and optional, so that it reverts to this class to determine the type of controls to render.

}) : super(key: key);

final ControlsType controlsType;

@override
Widget build(BuildContext context) {
switch (controlsType) {
case ControlsType.cupertino:
return const CupertinoControls(
backgroundColor: Color.fromRGBO(41, 41, 41, 0.7),
iconColor: Color.fromARGB(255, 200, 200, 200),
);
case ControlsType.material:
return const MaterialControls();
case ControlsType.materialDesktop:
return const MaterialDesktopControls();
case ControlsType.adaptive:
break;
}

Comment on lines +16 to +29
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having to duplicate code in this method, consider doing the following:

  • Instead of using a separate enum for this, you may want to use an optional and nullable TargetPlatform when creating this widget. That way if it exists, use that value, otherwise, fallback to the one from the theme.
  • Then you can determine the effective TargetPlatform to use based on the above and pass that into the switch statement:
final effectiveTargetPlatform = customPlatform ?? Theme.of(context).platform;
switch (effectiveTargetPlatform) {
  //...
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinaykumarrock986612 any updates?

switch (Theme.of(context).platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
Expand Down
11 changes: 6 additions & 5 deletions lib/src/player_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class PlayerWithControls extends StatelessWidget {
ChewieController chewieController,
) {
return chewieController.showControls
? chewieController.customControls ?? const AdaptiveControls()
? chewieController.customControls ??
AdaptiveControls(
controlsType: chewieController.controlsType,
)
: const SizedBox();
}

Expand All @@ -35,17 +38,15 @@ class PlayerWithControls extends StatelessWidget {
) {
return Stack(
children: <Widget>[
if (chewieController.placeholder != null)
chewieController.placeholder!,
if (chewieController.placeholder != null) chewieController.placeholder!,
InteractiveViewer(
transformationController: chewieController.transformationController,
maxScale: chewieController.maxScale,
panEnabled: chewieController.zoomAndPan,
scaleEnabled: chewieController.zoomAndPan,
child: Center(
child: AspectRatio(
aspectRatio: chewieController.aspectRatio ??
chewieController.videoPlayerController.value.aspectRatio,
aspectRatio: chewieController.aspectRatio ?? chewieController.videoPlayerController.value.aspectRatio,
child: VideoPlayer(chewieController.videoPlayerController),
),
),
Expand Down
Loading