@@ -248,18 +248,41 @@ class _ImageLightboxPageState extends State<_ImageLightboxPage> {
248
248
}
249
249
}
250
250
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 {
252
271
final VideoPlayerController controller;
253
272
254
- const _VideoPositionSliderControl ({
273
+ const VideoPositionSliderControl ({
274
+ super .key,
255
275
required this .controller,
256
276
});
257
277
258
278
@override
259
- State <_VideoPositionSliderControl > createState () => _VideoPositionSliderControlState ();
279
+ State <VideoPositionSliderControl > createState () => _VideoPositionSliderControlState ();
280
+
281
+ @visibleForTesting
282
+ static final kCurrentPositionLabelKey = UniqueKey ();
260
283
}
261
284
262
- class _VideoPositionSliderControlState extends State <_VideoPositionSliderControl > {
285
+ class _VideoPositionSliderControlState extends State <VideoPositionSliderControl > {
263
286
Duration _sliderValue = Duration .zero;
264
287
bool _isSliderDragging = false ;
265
288
@@ -293,22 +316,15 @@ class _VideoPositionSliderControlState extends State<_VideoPositionSliderControl
293
316
});
294
317
}
295
318
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
-
303
319
@override
304
320
Widget build (BuildContext context) {
305
321
final currentPosition = _isSliderDragging
306
322
? _sliderValue
307
323
: widget.controller.value.position;
308
324
309
325
return Row (children: [
310
- Text ( _formatDuration ( currentPosition) ,
311
- style : const TextStyle (color : Colors .white) ),
326
+ VideoDurationLabel ( currentPosition,
327
+ key : VideoPositionSliderControl .kCurrentPositionLabelKey ),
312
328
Expanded (
313
329
child: Slider (
314
330
value: currentPosition.inMilliseconds.toDouble (),
@@ -337,8 +353,7 @@ class _VideoPositionSliderControlState extends State<_VideoPositionSliderControl
337
353
},
338
354
),
339
355
),
340
- Text (_formatDuration (widget.controller.value.duration),
341
- style: const TextStyle (color: Colors .white)),
356
+ VideoDurationLabel (widget.controller.value.duration),
342
357
]);
343
358
}
344
359
}
@@ -427,7 +442,7 @@ class _VideoLightboxPageState extends State<VideoLightboxPage> with PerAccountSt
427
442
color: color,
428
443
elevation: elevation,
429
444
child: Column (mainAxisAlignment: MainAxisAlignment .end, children: [
430
- _VideoPositionSliderControl (controller: _controller! ),
445
+ VideoPositionSliderControl (controller: _controller! ),
431
446
IconButton (
432
447
onPressed: () {
433
448
if (_controller! .value.isPlaying) {
0 commit comments