Skip to content

Commit

Permalink
fix: replay not saved during animations (#2518)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind authored Dec 20, 2024
1 parent dd25e43 commit 9a5040f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
7 changes: 2 additions & 5 deletions flutter/lib/src/replay/replay_recorder.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:developer';

import 'package:flutter/scheduler.dart';
import 'package:meta/meta.dart';

import '../screenshot/recorder.dart';
Expand All @@ -18,9 +17,7 @@ class ReplayScreenshotRecorder extends ScreenshotRecorder {
@override
@protected
Future<void> executeTask(void Function() task, Flow flow) {
// Schedule the task to run between frames, when the app is idle.
return options.bindingUtils.instance
?.scheduleTask<void>(task, Priority.idle, flow: flow) ??
Future.sync(task);
// Future() schedules the task to be executed asynchronously with TImer.run.
return Future(task);
}
}
7 changes: 5 additions & 2 deletions flutter/lib/src/screenshot/recorder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ class ScreenshotRecorder {
}

@protected
Future<void> executeTask(void Function() task, Flow flow) =>
Future.sync(task);
Future<void> 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<WidgetFilterItem>? _obscureSync(_Capture<dynamic> capture) {
if (_maskingConfig != null) {
Expand Down
15 changes: 5 additions & 10 deletions flutter/test/screenshot/recorder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void main() async {
});

expect(
fixture.capture(),
fixture.capture,
throwsA(predicate(
(Exception e) => e.toString().contains('testing masking error'))));
});
Expand Down Expand Up @@ -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<String?> capture() async {
final future = sut.capture<String?>(
(Image image) => Future.value("${image.width}x${image.height}"));
await _tester.idle();
return future;
}
Future<String?> capture() => sut.capture<String?>(
(Image image) => Future.value("${image.width}x${image.height}"));
}

0 comments on commit 9a5040f

Please sign in to comment.