attachIntegrationScreenshot function
Future<bool>
attachIntegrationScreenshot({
- String name = 'screenshot',
- String? fileName,
- WidgetTester? tester,
Captures a device screenshot via IntegrationTestWidgetsFlutterBinding
and attaches the PNG (Android integration_test host/device path).
On Android call IntegrationTestWidgetsFlutterBinding.convertFlutterSurfaceToImage
first, then pump a frame (tester) before takeScreenshot. Prefer
attachScreenshot with a RepaintBoundary when you already hold a
WidgetTester — it avoids the Android surface conversion path.
Import package:tracera_flutter/integration.dart from an
integration_test/ suite. Widget tests should use attachScreenshot
on the main barrel instead.
Implementation
Future<bool> attachIntegrationScreenshot({
String name = 'screenshot',
String? fileName,
WidgetTester? tester,
}) async {
final binding = IntegrationTestWidgetsFlutterBinding.instance;
await binding.convertFlutterSurfaceToImage();
if (tester != null) {
await tester.pumpAndSettle();
}
final List<int> bytes = await binding.takeScreenshot(name);
if (bytes.isEmpty) return false;
attachScreenshotBytes(bytes, fileName: fileName ?? '$name.png');
return true;
}