painter_test.dart 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * QR.Flutter
  3. * Copyright (c) 2019 the QR.Flutter authors.
  4. * See LICENSE for distribution and usage details.
  5. */
  6. import 'dart:typed_data';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter_test/flutter_test.dart';
  9. // ignore: directives_ordering
  10. import 'package:fis_lib_qrcode/qr_flutter.dart';
  11. void main() {
  12. testWidgets('QrPainter generates correct image', (tester) async {
  13. final painter = QrPainter(
  14. data: 'The painter is this thing',
  15. version: QrVersions.auto,
  16. gapless: true,
  17. errorCorrectionLevel: QrErrorCorrectLevel.L,
  18. );
  19. ByteData? imageData;
  20. await tester.runAsync(() async {
  21. imageData = await painter.toImageData(600.0);
  22. });
  23. final imageBytes = imageData!.buffer.asUint8List();
  24. final widget = Center(
  25. child: RepaintBoundary(
  26. child: Container(
  27. width: 600,
  28. height: 600,
  29. child: Image.memory(imageBytes),
  30. ),
  31. ),
  32. );
  33. await tester.pumpWidget(widget);
  34. await tester.pumpAndSettle();
  35. await expectLater(
  36. find.byType(RepaintBoundary),
  37. matchesGoldenFile('./.golden/qr_painter_golden.png'),
  38. );
  39. });
  40. }