diff --git a/flutter/lib/src/replay/replay_recorder.dart b/flutter/lib/src/replay/replay_recorder.dart index e8684d9024..360ce53a5e 100644 --- a/flutter/lib/src/replay/replay_recorder.dart +++ b/flutter/lib/src/replay/replay_recorder.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'dart:developer'; -import 'package:flutter/scheduler.dart'; import 'package:meta/meta.dart'; import '../screenshot/recorder.dart'; @@ -18,9 +17,7 @@ class ReplayScreenshotRecorder extends ScreenshotRecorder { @override @protected Future executeTask(void Function() task, Flow flow) { - // Schedule the task to run between frames, when the app is idle. - return options.bindingUtils.instance - ?.scheduleTask(task, Priority.idle, flow: flow) ?? - Future.sync(task); + // Future() schedules the task to be executed asynchronously with TImer.run. + return Future(task); } } diff --git a/flutter/lib/src/screenshot/recorder.dart b/flutter/lib/src/screenshot/recorder.dart index 3a833a8828..0b85abe74b 100644 --- a/flutter/lib/src/screenshot/recorder.dart +++ b/flutter/lib/src/screenshot/recorder.dart @@ -111,8 +111,11 @@ class ScreenshotRecorder { } @protected - Future executeTask(void Function() task, Flow flow) => - Future.sync(task); + Future executeTask(void Function() task, Flow flow) { + // Future.sync() starts executing the function synchronously, until the + // first await, i.e. it's the same as if the code was executed directly. + return Future.sync(task); + } List? _obscureSync(_Capture capture) { if (_maskingConfig != null) { diff --git a/flutter/test/screenshot/recorder_test.dart b/flutter/test/screenshot/recorder_test.dart index 4a9954092b..14ee2605ac 100644 --- a/flutter/test/screenshot/recorder_test.dart +++ b/flutter/test/screenshot/recorder_test.dart @@ -83,7 +83,7 @@ void main() async { }); expect( - fixture.capture(), + fixture.capture, throwsA(predicate( (Exception e) => e.toString().contains('testing masking error')))); }); @@ -130,23 +130,18 @@ class _Fixture { ScreenshotRecorderConfig(width: width, height: height), options); late final options = defaultTestOptions() ..bindingUtils = TestBindingWrapper(); - final WidgetTester _tester; final double? width; final double? height; - _Fixture(this._tester, {this.width, this.height}); + _Fixture({this.width, this.height}); static Future<_Fixture> create(WidgetTester tester, {double? width, double? height}) async { - final fixture = _Fixture(tester, width: width, height: height); + final fixture = _Fixture(width: width, height: height); await pumpTestElement(tester); return fixture; } - Future capture() async { - final future = sut.capture( - (Image image) => Future.value("${image.width}x${image.height}")); - await _tester.idle(); - return future; - } + Future capture() => sut.capture( + (Image image) => Future.value("${image.width}x${image.height}")); }