123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- /*
- * QR.Flutter
- * Copyright (c) 2019 the QR.Flutter authors.
- * See LICENSE for distribution and usage details.
- */
- import 'dart:io';
- import 'package:flutter/material.dart';
- import 'package:flutter_test/flutter_test.dart';
- // ignore: directives_ordering
- import 'package:fis_lib_qrcode/qr_flutter.dart';
- void main() {
- testWidgets('QrImageView generates correct image', (tester) async {
- final qrImage = MaterialApp(
- home: Center(
- child: RepaintBoundary(
- child: QrImageView(
- data: 'This is a test image',
- version: QrVersions.auto,
- gapless: true,
- errorCorrectionLevel: QrErrorCorrectLevel.L,
- ),
- ),
- ),
- );
- await tester.pumpWidget(qrImage);
- await expectLater(
- find.byType(QrImageView),
- matchesGoldenFile('./.golden/qr_image_golden.png'),
- );
- });
- testWidgets('QrImageView generates correct image with eye style',
- (tester) async {
- final qrImage = MaterialApp(
- home: Center(
- child: RepaintBoundary(
- child: QrImageView(
- data: 'This is a test image',
- version: QrVersions.auto,
- gapless: true,
- errorCorrectionLevel: QrErrorCorrectLevel.L,
- eyeStyle: const QrEyeStyle(
- eyeShape: QrEyeShape.circle,
- color: Colors.green,
- ),
- ),
- ),
- ),
- );
- await tester.pumpWidget(qrImage);
- await expectLater(
- find.byType(QrImageView),
- matchesGoldenFile('./.golden/qr_image_eye_styled_golden.png'),
- );
- });
- testWidgets('QrImageView generates correct image with data module style',
- (tester) async {
- final qrImage = MaterialApp(
- home: Center(
- child: RepaintBoundary(
- child: QrImageView(
- data: 'This is a test image',
- version: QrVersions.auto,
- gapless: true,
- errorCorrectionLevel: QrErrorCorrectLevel.L,
- dataModuleStyle: const QrDataModuleStyle(
- dataModuleShape: QrDataModuleShape.circle,
- color: Colors.blue,
- ),
- ),
- ),
- ),
- );
- await tester.pumpWidget(qrImage);
- await expectLater(
- find.byType(QrImageView),
- matchesGoldenFile('./.golden/qr_image_data_module_styled_golden.png'),
- );
- });
- testWidgets(
- 'QrImageView generates correct image with eye and data module sytle',
- (tester) async {
- final qrImage = MaterialApp(
- home: Center(
- child: RepaintBoundary(
- child: QrImageView(
- data: 'This is a test image',
- version: QrVersions.auto,
- gapless: true,
- errorCorrectionLevel: QrErrorCorrectLevel.L,
- eyeStyle: const QrEyeStyle(
- eyeShape: QrEyeShape.circle,
- color: Colors.green,
- ),
- dataModuleStyle: const QrDataModuleStyle(
- dataModuleShape: QrDataModuleShape.circle,
- color: Colors.blue,
- ),
- ),
- ),
- ),
- );
- await tester.pumpWidget(qrImage);
- await expectLater(
- find.byType(QrImageView),
- matchesGoldenFile('./.golden/qr_image_eye_data_module_styled_golden.png'),
- );
- });
- testWidgets(
- 'QrImageView does not apply eye and data module color when foreground '
- 'color is also specified', (tester) async {
- final qrImage = MaterialApp(
- home: Center(
- child: RepaintBoundary(
- child: QrImageView(
- data: 'This is a test image',
- version: QrVersions.auto,
- gapless: true,
- foregroundColor: Colors.red,
- errorCorrectionLevel: QrErrorCorrectLevel.L,
- eyeStyle: const QrEyeStyle(
- eyeShape: QrEyeShape.circle,
- color: Colors.green,
- ),
- dataModuleStyle: const QrDataModuleStyle(
- dataModuleShape: QrDataModuleShape.circle,
- color: Colors.blue,
- ),
- ),
- ),
- ),
- );
- await tester.pumpWidget(qrImage);
- await expectLater(
- find.byType(QrImageView),
- matchesGoldenFile('./.golden/qr_image_foreground_colored_golden.png'),
- );
- });
- testWidgets('QrImageView generates correct image with logo', (tester) async {
- await pumpWidgetWithImages(
- tester,
- MaterialApp(
- home: Center(
- child: RepaintBoundary(
- child: QrImageView(
- data: 'This is a a qr code with a logo',
- version: QrVersions.auto,
- gapless: true,
- errorCorrectionLevel: QrErrorCorrectLevel.L,
- embeddedImage: FileImage(File('test/.images/logo_yakka.png')),
- ),
- ),
- ),
- ),
- ['test/.images/logo_yakka.png'],
- );
- await tester.pumpAndSettle();
- await expectLater(
- find.byType(QrImageView),
- matchesGoldenFile('./.golden/qr_image_logo_golden.png'),
- );
- });
- }
- /// Pre-cache images to make sure they show up in golden tests.
- ///
- /// See https://github.com/flutter/flutter/issues/36552 for more info.
- Future<void> pumpWidgetWithImages(
- WidgetTester tester,
- Widget widget,
- List<String> assetNames,
- ) async {
- Future<void>? precacheFuture;
- await tester.pumpWidget(
- Builder(builder: (buildContext) {
- precacheFuture = tester.runAsync(() async {
- await Future.wait([
- for (final assetName in assetNames)
- precacheImage(FileImage(File(assetName)), buildContext),
- ]);
- });
- return widget;
- }),
- );
- await precacheFuture;
- }
- Widget buildTestableWidget(Widget widget) {
- return MediaQuery(data: MediaQueryData(), child: MaterialApp(home: widget));
- }
|