@@ -240,6 +240,16 @@ void main() {
240
240
check (platform.position).equals (video);
241
241
}
242
242
243
+ /// Like [checkPositions] , but expressed in units of [kTestVideoDuration] .
244
+ void checkPositionsRelative (WidgetTester tester, {
245
+ required double slider,
246
+ required double video,
247
+ }) {
248
+ checkPositions (tester,
249
+ slider: kTestVideoDuration * slider,
250
+ video: kTestVideoDuration * video);
251
+ }
252
+
243
253
(Offset , Offset ) calculateSliderDimensions (WidgetTester tester) {
244
254
const padding = 24.0 ;
245
255
final rect = tester.getRect (find.byType (Slider ));
@@ -306,9 +316,7 @@ void main() {
306
316
307
317
await tester.pump (kTestVideoDuration * 0.5 );
308
318
platform.pumpEvents ();
309
- checkPositions (tester,
310
- slider: kTestVideoDuration * 0.5 ,
311
- video: kTestVideoDuration * 0.5 );
319
+ checkPositionsRelative (tester, slider: 0.5 , video: 0.5 );
312
320
check (platform.isCompleted).isFalse ();
313
321
check (platform.isPlaying).isTrue ();
314
322
@@ -324,18 +332,14 @@ void main() {
324
332
// At exactly the end of the video.
325
333
await tester.pump (const Duration (milliseconds: 500 ));
326
334
platform.pumpEvents ();
327
- checkPositions (tester,
328
- slider: kTestVideoDuration,
329
- video: kTestVideoDuration);
335
+ checkPositionsRelative (tester, slider: 1.0 , video: 1.0 );
330
336
check (platform.isCompleted).isTrue (); // completed
331
337
check (platform.isPlaying).isFalse (); // stopped playing
332
338
333
339
// After the video ended.
334
340
await tester.pump (const Duration (milliseconds: 500 ));
335
341
platform.pumpEvents ();
336
- checkPositions (tester,
337
- slider: kTestVideoDuration,
338
- video: kTestVideoDuration);
342
+ checkPositionsRelative (tester, slider: 1.0 , video: 1.0 );
339
343
check (platform.isCompleted).isTrue ();
340
344
check (platform.isPlaying).isFalse ();
341
345
});
@@ -350,33 +354,23 @@ void main() {
350
354
// gesture increments.
351
355
final gesture = await tester.startGesture (trackStartPos);
352
356
await tester.pump ();
353
- checkPositions (tester,
354
- slider: Duration .zero,
355
- video: Duration .zero);
357
+ checkPositionsRelative (tester, slider: 0.0 , video: 0.0 );
356
358
357
359
await gesture.moveBy (trackLength * 0.2 );
358
360
await tester.pump ();
359
- checkPositions (tester,
360
- slider: kTestVideoDuration * 0.2 ,
361
- video: Duration .zero);
361
+ checkPositionsRelative (tester, slider: 0.2 , video: 0.0 );
362
362
363
363
await gesture.moveBy (trackLength * 0.4 );
364
364
await tester.pump ();
365
- checkPositions (tester,
366
- slider: kTestVideoDuration * 0.6 ,
367
- video: Duration .zero);
365
+ checkPositionsRelative (tester, slider: 0.6 , video: 0.0 );
368
366
369
- await gesture.moveBy (- trackLength * 0.2 );
367
+ await gesture.moveBy (trackLength * - 0.2 );
370
368
await tester.pump ();
371
- checkPositions (tester,
372
- slider: kTestVideoDuration * 0.4 ,
373
- video: Duration .zero);
369
+ checkPositionsRelative (tester, slider: 0.4 , video: 0.0 );
374
370
375
371
await gesture.up ();
376
372
await tester.pump ();
377
- checkPositions (tester,
378
- slider: kTestVideoDuration * 0.4 ,
379
- video: kTestVideoDuration * 0.4 );
373
+ checkPositionsRelative (tester, slider: 0.4 , video: 0.4 );
380
374
381
375
// Verify seekTo is called only once.
382
376
check (platform.callLog.where ((v) => v == 'seekTo' ).length).equals (1 );
@@ -390,21 +384,15 @@ void main() {
390
384
391
385
final gesture = await tester.startGesture (trackStartPos);
392
386
await tester.pump ();
393
- checkPositions (tester,
394
- slider: Duration .zero,
395
- video: Duration .zero);
387
+ checkPositionsRelative (tester, slider: 0.0 , video: 0.0 );
396
388
397
389
await gesture.moveBy (trackLength * 0.5 );
398
390
await tester.pump ();
399
- checkPositions (tester,
400
- slider: kTestVideoDuration * 0.5 ,
401
- video: Duration .zero);
391
+ checkPositionsRelative (tester, slider: 0.5 , video: 0.0 );
402
392
403
393
await gesture.up ();
404
394
await tester.pump ();
405
- checkPositions (tester,
406
- slider: kTestVideoDuration * 0.5 ,
407
- video: kTestVideoDuration * 0.5 );
395
+ checkPositionsRelative (tester, slider: 0.5 , video: 0.5 );
408
396
409
397
final basePosition = kTestVideoDuration * 0.5 ;
410
398
Duration actualElapsed = basePosition;
@@ -424,9 +412,7 @@ void main() {
424
412
if (actualElapsed.inMilliseconds % 500 == 0 ) {
425
413
lastPolled += const Duration (milliseconds: 500 );
426
414
}
427
- checkPositions (tester,
428
- slider: lastPolled,
429
- video: actualElapsed);
415
+ checkPositions (tester, slider: lastPolled, video: actualElapsed);
430
416
}
431
417
});
432
418
});
0 commit comments