Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,14 @@ class ChewieController extends ChangeNotifier {
/// Whether or not to show the controls at all
final bool showControls;

/// Controller to pass into the [InteractiveViewer] component
/// Controller to pass into the [InteractiveViewer] component.
/// If it is required to control the transformation only via the controller,
/// `zoomAndPan` should be set to false.
final TransformationController? transformationController;

/// Whether or not to allow zooming and panning
/// Whether or not to allow zooming and panning.
/// This can still be false, and the `transformationController` can be used to control the
/// transformation.
final bool zoomAndPan;

/// Max scale when zooming
Expand Down
107 changes: 54 additions & 53 deletions lib/src/player_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,66 +33,67 @@ class PlayerWithControls extends StatelessWidget {
ChewieController chewieController,
BuildContext context,
) {
final playerNotifier =
Provider.of<PlayerNotifier>(context, listen: false);
return InteractiveViewer(
transformationController: chewieController.transformationController,
maxScale: chewieController.maxScale,
panEnabled: chewieController.zoomAndPan,
scaleEnabled: chewieController.zoomAndPan,
onInteractionUpdate: chewieController.zoomAndPan
? (_) => playerNotifier.hideStuff = true
: null,
onInteractionEnd: chewieController.zoomAndPan
? (_) => playerNotifier.hideStuff = false
: null,
child: Stack(
children: [
if (chewieController.placeholder != null)
chewieController.placeholder!,
Center(
child: AspectRatio(
aspectRatio: chewieController.aspectRatio ??
chewieController.videoPlayerController.value.aspectRatio,
child: VideoPlayer(chewieController.videoPlayerController),
),
final playerNotifier = Provider.of<PlayerNotifier>(context, listen: false);
final child = Stack(
children: [
if (chewieController.placeholder != null) chewieController.placeholder!,
Center(
child: AspectRatio(
aspectRatio: chewieController.aspectRatio ??
chewieController.videoPlayerController.value.aspectRatio,
child: VideoPlayer(chewieController.videoPlayerController),
),
if (chewieController.overlay != null) chewieController.overlay!,
if (Theme.of(context).platform != TargetPlatform.iOS)
Consumer<PlayerNotifier>(
builder: (
BuildContext context,
PlayerNotifier notifier,
Widget? widget,
) =>
Visibility(
visible: !notifier.hideStuff,
child: AnimatedOpacity(
opacity: notifier.hideStuff ? 0.0 : 0.8,
duration: const Duration(
milliseconds: 250,
),
child: const DecoratedBox(
decoration: BoxDecoration(color: Colors.black54),
child: SizedBox.expand(),
),
),
if (chewieController.overlay != null) chewieController.overlay!,
if (Theme.of(context).platform != TargetPlatform.iOS)
Consumer<PlayerNotifier>(
builder: (
BuildContext context,
PlayerNotifier notifier,
Widget? widget,
) =>
Visibility(
visible: !notifier.hideStuff,
child: AnimatedOpacity(
opacity: notifier.hideStuff ? 0.0 : 0.8,
duration: const Duration(
milliseconds: 250,
),
child: const DecoratedBox(
decoration: BoxDecoration(color: Colors.black54),
child: SizedBox.expand(),
),
),
),
if (!chewieController.isFullScreen)
buildControls(context, chewieController)
else
SafeArea(
bottom: false,
child: buildControls(context, chewieController),
),
],
),
),
if (!chewieController.isFullScreen)
buildControls(context, chewieController)
else
SafeArea(
bottom: false,
child: buildControls(context, chewieController),
),
],
);

if (chewieController.zoomAndPan || chewieController.transformationController != null) {
return InteractiveViewer(
transformationController: chewieController.transformationController,
maxScale: chewieController.maxScale,
panEnabled: chewieController.zoomAndPan,
scaleEnabled: chewieController.zoomAndPan,
onInteractionUpdate:
chewieController.zoomAndPan ? (_) => playerNotifier.hideStuff = true : null,
onInteractionEnd:
chewieController.zoomAndPan ? (_) => playerNotifier.hideStuff = false : null,
child: child,
);
}

return child;
}

return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
return Center(
child: SizedBox(
height: constraints.maxHeight,
Expand Down
Loading