attachIntegrationScreenshot function

Future<bool> attachIntegrationScreenshot({
  1. String name = 'screenshot',
  2. String? fileName,
  3. 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 {
  // Soft: device / binding failures must not fail the suite (attachScreenshot parity).
  try {
    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;
  } catch (_) {
    return false;
  }
}