Skip to content

Commit e453648

Browse files
lightbox [nfc]: Pull out VideoDurationLabel
In addition also make VideoPositionSliderControl public for testing visibility.
1 parent 10d0fe8 commit e453648

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

lib/widgets/lightbox.dart

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,41 @@ class _ImageLightboxPageState extends State<_ImageLightboxPage> {
248248
}
249249
}
250250

251-
class _VideoPositionSliderControl extends StatefulWidget {
251+
class VideoDurationLabel extends StatelessWidget {
252+
const VideoDurationLabel(this.duration, {super.key});
253+
254+
final Duration duration;
255+
256+
static String _formatDuration(Duration value) {
257+
final hours = value.inHours.toString().padLeft(2, '0');
258+
final minutes = value.inMinutes.remainder(60).toString().padLeft(2, '0');
259+
final seconds = value.inSeconds.remainder(60).toString().padLeft(2, '0');
260+
return '${hours == '00' ? '' : '$hours:'}$minutes:$seconds';
261+
}
262+
263+
@override
264+
Widget build(BuildContext context) {
265+
return Text(_formatDuration(duration),
266+
style: const TextStyle(color: Colors.white));
267+
}
268+
}
269+
270+
class VideoPositionSliderControl extends StatefulWidget {
252271
final VideoPlayerController controller;
253272

254-
const _VideoPositionSliderControl({
273+
const VideoPositionSliderControl({
274+
super.key,
255275
required this.controller,
256276
});
257277

258278
@override
259-
State<_VideoPositionSliderControl> createState() => _VideoPositionSliderControlState();
279+
State<VideoPositionSliderControl> createState() => _VideoPositionSliderControlState();
280+
281+
@visibleForTesting
282+
static final kCurrentPositionLabelKey = UniqueKey();
260283
}
261284

262-
class _VideoPositionSliderControlState extends State<_VideoPositionSliderControl> {
285+
class _VideoPositionSliderControlState extends State<VideoPositionSliderControl> {
263286
Duration _sliderValue = Duration.zero;
264287
bool _isSliderDragging = false;
265288

@@ -293,22 +316,15 @@ class _VideoPositionSliderControlState extends State<_VideoPositionSliderControl
293316
});
294317
}
295318

296-
static String _formatDuration(Duration value) {
297-
final hours = value.inHours.toString().padLeft(2, '0');
298-
final minutes = value.inMinutes.remainder(60).toString().padLeft(2, '0');
299-
final seconds = value.inSeconds.remainder(60).toString().padLeft(2, '0');
300-
return '${hours == '00' ? '' : '$hours:'}$minutes:$seconds';
301-
}
302-
303319
@override
304320
Widget build(BuildContext context) {
305321
final currentPosition = _isSliderDragging
306322
? _sliderValue
307323
: widget.controller.value.position;
308324

309325
return Row(children: [
310-
Text(_formatDuration(currentPosition),
311-
style: const TextStyle(color: Colors.white)),
326+
VideoDurationLabel(currentPosition,
327+
key: VideoPositionSliderControl.kCurrentPositionLabelKey),
312328
Expanded(
313329
child: Slider(
314330
value: currentPosition.inMilliseconds.toDouble(),
@@ -337,8 +353,7 @@ class _VideoPositionSliderControlState extends State<_VideoPositionSliderControl
337353
},
338354
),
339355
),
340-
Text(_formatDuration(widget.controller.value.duration),
341-
style: const TextStyle(color: Colors.white)),
356+
VideoDurationLabel(widget.controller.value.duration),
342357
]);
343358
}
344359
}
@@ -427,7 +442,7 @@ class _VideoLightboxPageState extends State<VideoLightboxPage> with PerAccountSt
427442
color: color,
428443
elevation: elevation,
429444
child: Column(mainAxisAlignment: MainAxisAlignment.end, children: [
430-
_VideoPositionSliderControl(controller: _controller!),
445+
VideoPositionSliderControl(controller: _controller!),
431446
IconButton(
432447
onPressed: () {
433448
if (_controller!.value.isPlaying) {

0 commit comments

Comments
 (0)