startRecording method
Start recording — call this before interacting with a screen
Implementation
Future<void> startRecording() async {
_frameEvents.clear();
// Subscribe to Flutter.Frame extension events. streamListen throws
// RPCError 103 when the stream is already subscribed (another capture,
// or a previous run) — that's fine, our listener still receives events.
try {
await vmService.streamListen(EventStreams.kExtension);
} on RPCError catch (e) {
if (e.code != 103) rethrow;
}
_subscription ??= vmService.onExtensionEvent.listen((event) {
if (event.extensionKind != 'Flutter.Frame') return;
final data = event.extensionData?.data;
if (data == null) return;
final frame = frameFromFlutterFrameEvent(data);
if (frame != null) _frameEvents.add(frame);
});
// Timeline recording stays on as the fallback source.
await vmService.clearVMTimeline();
await vmService.setVMTimelineFlags(['Dart', 'Embedder', 'GC']);
print(' ⏱️ Performance recording started...');
}