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 4 commits 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: 4 additions & 2 deletions example/lib/animation_player/landscape_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ class AnimationPlayerLandscapeControls extends StatelessWidget {
Expanded(
child: Container(),
),
FlickFullScreenToggle(
size: 30,
SafeArea(
child: FlickFullScreenToggle(
size: 100,
),
),
],
),
Expand Down
12 changes: 8 additions & 4 deletions example/lib/animation_player/portrait_video_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ class AnimationPlayerPortraitVideoControls extends StatelessWidget {
showIfVideoNotInitialized: false,
child: FlickSoundToggle(),
),
FlickAutoHideChild(
autoHide: false,
showIfVideoNotInitialized: false,
child: FlickFullScreenToggle(),
SafeArea(
child: FlickAutoHideChild(
autoHide: false,
showIfVideoNotInitialized: false,
child: FlickFullScreenToggle(
size: 100,
),
),
),
],
),
Expand Down
6 changes: 4 additions & 2 deletions example/lib/custom_orientation_player/controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ class CustomOrientationControls extends StatelessWidget {
Expanded(
child: Container(),
),
FlickFullScreenToggle(
size: iconSize,
SafeArea(
child: FlickFullScreenToggle(
size: 100,
),
),
],
),
Expand Down
6 changes: 4 additions & 2 deletions example/lib/web_video_player/web_video_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ class WebVideoControl extends StatelessWidget {
Expanded(
child: Container(),
),
FlickFullScreenToggle(
size: iconSize,
SafeArea(
child: FlickFullScreenToggle(
size: 100,
),
),
],
),
Expand Down
29 changes: 21 additions & 8 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 Expand Up @@ -100,8 +111,10 @@ class FlickPortraitControls extends StatelessWidget {
SizedBox(
width: iconSize / 2,
),
FlickFullScreenToggle(
size: iconSize,
SafeArea(
child: FlickFullScreenToggle(
size: 100,
),
),
],
),
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
28 changes: 15 additions & 13 deletions lib/src/widgets/flick_full_screen_toggle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,21 @@ class FlickFullScreenToggle extends StatelessWidget {
? exitFullScreenWidget
: enterFullScreenWidget;

return GestureDetector(
key: key,
onTap: () {
if (toggleFullscreen != null) {
toggleFullscreen!();
} else {
controlManager.toggleFullscreen();
}
},
child: Container(
padding: padding,
decoration: decoration,
child: child,
return SafeArea(
child: GestureDetector(
key: key,
onTap: () {
if (toggleFullscreen != null) {
toggleFullscreen!();
} else {
controlManager.toggleFullscreen();
}
},
child: Container(
padding: padding,
decoration: decoration,
child: child,
),
),
);
}
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