Skip to content

Commit 73cdda0

Browse files
committed
feat: initial fullscreen impl in Video widget
1 parent 12caada commit 73cdda0

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

lib/src/widgets/controls.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class Control extends StatefulWidget {
4141
required this.volumeInactiveColor,
4242
required this.volumeBackgroundColor,
4343
required this.volumeThumbColor,
44+
this.enterFullscreen,
45+
this.exitFullscreen,
46+
this.isFullscreen: false,
47+
this.showFullscreenButton: false,
4448
}) : super(key: key);
4549

4650
final Widget child;
@@ -57,6 +61,10 @@ class Control extends StatefulWidget {
5761
final Color? volumeInactiveColor;
5862
final Color? volumeBackgroundColor;
5963
final Color? volumeThumbColor;
64+
final VoidCallback? enterFullscreen;
65+
final VoidCallback? exitFullscreen;
66+
final bool isFullscreen;
67+
final bool showFullscreenButton;
6068

6169
@override
6270
ControlState createState() => ControlState();
@@ -307,6 +315,23 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
307315
],
308316
),
309317
),
318+
if (widget.showFullscreenButton)
319+
Positioned(
320+
left: 15,
321+
bottom: 12.5,
322+
child: IconButton(
323+
onPressed: !widget.isFullscreen
324+
? widget.enterFullscreen
325+
: widget.exitFullscreen,
326+
iconSize: 24,
327+
icon: Icon(
328+
!widget.isFullscreen
329+
? Icons.fullscreen
330+
: Icons.fullscreen_exit,
331+
color: Colors.white,
332+
),
333+
),
334+
),
310335
],
311336
),
312337
),

lib/src/widgets/video.dart

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import 'dart:ui' as ui;
2323
import 'package:flutter/material.dart';
2424
import 'package:dart_vlc/dart_vlc.dart';
2525
import 'package:dart_vlc/src/widgets/controls.dart';
26+
import 'package:window_manager/window_manager.dart';
2627

2728
/// Internally used map to keep [GlobalKey]s for [Video]'s [ControlState]s.
2829
Map<int, GlobalKey<ControlState>> controls = {};
@@ -100,6 +101,8 @@ class Video extends StatefulWidget {
100101
this.showTimeLeft = false,
101102
this.progressBarTextStyle = const TextStyle(),
102103
this.filterQuality = FilterQuality.low,
104+
this.showFullscreenButton = false,
105+
this.fillColor: Colors.black,
103106
}) : player = player ?? players[playerId]! as Player,
104107
super(key: key);
105108

@@ -168,6 +171,12 @@ class Video extends StatefulWidget {
168171
/// instead of the total time, set this to true
169172
final bool showTimeLeft;
170173

174+
/// Whether to show the fullscreen button.
175+
final bool showFullscreenButton;
176+
177+
/// Fill color.
178+
final Color fillColor;
179+
171180
_VideoStateBase createState() => _VideoStateTexture();
172181
}
173182

@@ -183,17 +192,67 @@ abstract class _VideoStateBase extends State<Video>
183192
if (widget.showControls) controls[playerId] = controlKey;
184193
}
185194

195+
void enterFullscreen() async {
196+
await windowManager.ensureInitialized();
197+
await windowManager.setFullScreen(true);
198+
Navigator.of(context, rootNavigator: true).push(
199+
PageRouteBuilder(
200+
transitionDuration: Duration.zero,
201+
reverseTransitionDuration: Duration.zero,
202+
pageBuilder: (_, __, ___) => Scaffold(
203+
body: Container(
204+
height: double.infinity,
205+
width: double.infinity,
206+
color: widget.fillColor,
207+
child: widget.showControls
208+
? Control(
209+
player: widget.player,
210+
enterFullscreen: enterFullscreen,
211+
exitFullscreen: exitFullscreen,
212+
isFullscreen: true,
213+
progressBarThumbRadius: widget.progressBarThumbRadius,
214+
progressBarThumbGlowRadius:
215+
widget.progressBarThumbGlowRadius,
216+
progressBarActiveColor: widget.progressBarActiveColor,
217+
progressBarInactiveColor: widget.progressBarInactiveColor,
218+
progressBarThumbColor: widget.progressBarThumbColor,
219+
progressBarThumbGlowColor: widget.progressBarThumbGlowColor,
220+
volumeActiveColor: widget.volumeActiveColor,
221+
volumeInactiveColor: widget.volumeInactiveColor,
222+
volumeBackgroundColor: widget.volumeBackgroundColor,
223+
volumeThumbColor: widget.volumeThumbColor,
224+
showTimeLeft: widget.showTimeLeft,
225+
progressBarTextStyle: widget.progressBarTextStyle,
226+
child: present(),
227+
)
228+
: present(),
229+
),
230+
),
231+
),
232+
);
233+
}
234+
235+
void exitFullscreen() async {
236+
await windowManager.ensureInitialized();
237+
await windowManager.setFullScreen(false);
238+
Navigator.of(context, rootNavigator: false).pop();
239+
}
240+
186241
@override
187242
Widget build(BuildContext context) {
188243
super.build(context);
189244
return Container(
190245
width: widget.width ?? double.infinity,
191246
height: widget.height ?? double.infinity,
192-
color: Colors.transparent,
247+
color: widget.fillColor,
193248
child: widget.showControls
194249
? Control(
195250
key: controlKey,
196251
player: widget.player,
252+
enterFullscreen: enterFullscreen,
253+
exitFullscreen: exitFullscreen,
254+
isFullscreen: false,
255+
showFullscreenButton: widget.showFullscreenButton,
197256
progressBarThumbRadius: widget.progressBarThumbRadius,
198257
progressBarThumbGlowRadius: widget.progressBarThumbGlowRadius,
199258
progressBarActiveColor: widget.progressBarActiveColor,

0 commit comments

Comments
 (0)