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

Update for the overlay builder #713

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
6 changes: 6 additions & 0 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class ChewieController extends ChangeNotifier {
this.materialProgressColors,
this.placeholder,
this.overlay,
this.overlayBuilder,
this.showControlsOnInitialize = true,
this.showOptions = true,
this.optionsBuilder,
Expand Down Expand Up @@ -304,6 +305,7 @@ class ChewieController extends ChangeNotifier {
ChewieProgressColors? materialProgressColors,
Widget? placeholder,
Widget? overlay,
Widget Function(BuildContext)? overlayBuilder,
bool? showControlsOnInitialize,
bool? showOptions,
Future<void> Function(BuildContext, List<OptionItem>)? optionsBuilder,
Expand Down Expand Up @@ -354,6 +356,7 @@ class ChewieController extends ChangeNotifier {
materialProgressColors ?? this.materialProgressColors,
placeholder: placeholder ?? this.placeholder,
overlay: overlay ?? this.overlay,
overlayBuilder: overlayBuilder ?? this.overlayBuilder,
showControlsOnInitialize:
showControlsOnInitialize ?? this.showControlsOnInitialize,
showOptions: showOptions ?? this.showOptions,
Expand Down Expand Up @@ -390,6 +393,9 @@ class ChewieController extends ChangeNotifier {

static const defaultHideControlsTimer = Duration(seconds: 3);

/// Define here your own Widget on how your overlay will look
Widget Function(BuildContext context)? overlayBuilder;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be final since we're trying to make the controller immutable.


/// If false, the options button in MaterialUI and MaterialDesktopUI
/// won't be shown.
final bool showOptions;
Expand Down
12 changes: 11 additions & 1 deletion lib/src/player_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ class PlayerWithControls extends StatelessWidget {
return width > height ? width / height : height / width;
}

Widget buildOverlay(BuildContext context) {
if(chewieController.overlayBuilder != null) {
return chewieController.overlayBuilder!(context);
}
if (chewieController.overlay != null) {
return chewieController.overlay!;
}
return const SizedBox.shrink();
Comment on lines +24 to +30
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be chained as an if-else statement, with it defaulting to SizedBox.shrink().

For bonus credit, instead of using a function to compute the correct Widget to return, why not move it into a standalone widget that takes in the current controller and computes it when build is called on it.

}

Widget buildControls(
BuildContext context,
ChewieController chewieController,
Expand Down Expand Up @@ -50,7 +60,7 @@ class PlayerWithControls extends StatelessWidget {
),
),
),
if (chewieController.overlay != null) chewieController.overlay!,
buildOverlay(context),
if (Theme.of(context).platform != TargetPlatform.iOS)
Consumer<PlayerNotifier>(
builder: (
Expand Down