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

Added ability to pass the aspect ratio and controls background #287

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
23 changes: 17 additions & 6 deletions lib/src/controls/flick_portrait_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import 'package:flick_video_player/flick_video_player.dart';

/// Default portrait controls.
class FlickPortraitControls extends StatelessWidget {
const FlickPortraitControls(
{Key? key,
this.iconSize = 20,
this.fontSize = 12,
this.progressBarSettings})
: super(key: key);
const FlickPortraitControls({
Key? key,
this.iconSize = 20,
this.fontSize = 12,
this.progressBarSettings,
this.controlsBackgroundColor,
}) : super(key: key);

/// Icon size.
///
Expand All @@ -20,13 +21,23 @@ class FlickPortraitControls extends StatelessWidget {
/// This size is used for all the text.
final double fontSize;

final Color? controlsBackgroundColor;

/// [FlickProgressBarSettings] settings.
final FlickProgressBarSettings? progressBarSettings;

@override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
if (controlsBackgroundColor != null)
Positioned.fill(
child: FlickAutoHideChild(
child: Container(
color: controlsBackgroundColor,
),
),
),
Positioned.fill(
child: FlickShowControlsAction(
child: FlickSeekVideoAction(
Expand Down
4 changes: 4 additions & 0 deletions lib/src/controls/flick_video_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class FlickVideoWithControls extends StatefulWidget {
fontSize: 12,
),
this.aspectRatioWhenLoading = 16 / 9,
this.aspectRatio,
this.willVideoPlayerControllerChange = true,
this.closedCaptionTextStyle = const TextStyle(
color: Colors.white,
Expand Down Expand Up @@ -81,6 +82,8 @@ class FlickVideoWithControls extends StatefulWidget {
/// Once the video is initialized, video determines size taken.
final double aspectRatioWhenLoading;

final double? aspectRatio;

/// If false videoPlayerController will not be updated.
final bool willVideoPlayerControllerChange;

Expand Down Expand Up @@ -125,6 +128,7 @@ class _FlickVideoWithControlsState extends State<FlickVideoWithControls> {
videoPlayerController: _videoPlayerController!,
fit: widget.videoFit,
aspectRatioWhenLoading: widget.aspectRatioWhenLoading,
aspectRatio: widget.aspectRatio,
)
: widget.playerLoadingFallback,
),
Expand Down
10 changes: 6 additions & 4 deletions lib/src/widgets/flick_native_video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ class FlickNativeVideoPlayer extends StatelessWidget {
Key? key,
this.fit,
this.aspectRatioWhenLoading,
this.aspectRatio,
required this.videoPlayerController,
}) : super(key: key);

final BoxFit? fit;
final double? aspectRatioWhenLoading;
final double? aspectRatio;
final VideoPlayerController? videoPlayerController;

@override
Expand All @@ -23,15 +25,15 @@ class FlickNativeVideoPlayer extends StatelessWidget {

return LayoutBuilder(
builder: (context, size) {
double aspectRatio = (size.maxHeight == double.infinity ||
double usedAspectRatio = (size.maxHeight == double.infinity ||
size.maxWidth == double.infinity)
? (videoPlayerController?.value.isInitialized == true
? videoPlayerController?.value.aspectRatio
? aspectRatio ?? videoPlayerController?.value.aspectRatio
: aspectRatioWhenLoading!)!
: size.maxWidth / size.maxHeight;
: (aspectRatio ?? size.maxWidth / size.maxHeight);

return AspectRatio(
aspectRatio: aspectRatio,
aspectRatio: usedAspectRatio,
child: FittedBox(
fit: fit!,
child: videoPlayerController?.value.isInitialized == true
Expand Down