From 3dca2d10a9328c2d68e1bd2f5022ef4665b6d2cb Mon Sep 17 00:00:00 2001 From: FrenkyDema Date: Thu, 21 Mar 2024 08:36:40 +0100 Subject: [PATCH] Fix handle space in scan value Refactoring --- example/integration_test/plugin_integration_test.dart | 4 ++-- example/lib/main.dart | 4 +--- example/test/widget_test.dart | 4 ++-- lib/qrcode_barcode_scanner.dart | 4 ++-- test/qrcode_barcode_scanner_method_channel_test.dart | 9 ++++++--- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/example/integration_test/plugin_integration_test.dart b/example/integration_test/plugin_integration_test.dart index 642729f..7377ac3 100644 --- a/example/integration_test/plugin_integration_test.dart +++ b/example/integration_test/plugin_integration_test.dart @@ -6,7 +6,6 @@ // For more information about Flutter integration tests, please see // https://docs.flutter.dev/cookbook/testing/integration/introduction - import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; @@ -16,7 +15,8 @@ void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); testWidgets('getPlatformVersion test', (WidgetTester tester) async { - final QrcodeBarcodeScanner plugin = QrcodeBarcodeScanner(onScannedCallback: (String scannedCode) { }); + final QrcodeBarcodeScanner plugin = + QrcodeBarcodeScanner(onScannedCallback: (String scannedCode) {}); final String? version = await plugin.getPlatformVersion(); // The version string depends on the host platform running the test, so // just assert that some non-empty string is returned. diff --git a/example/lib/main.dart b/example/lib/main.dart index b66425c..e716228 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -16,7 +16,6 @@ class _MyAppState extends State { String? _scanValue; void setScannedValue(String value) { - debugPrint("$value ${value.length}"); setState(() { _scanValue = value; }); @@ -27,7 +26,6 @@ class _MyAppState extends State { super.initState(); QrcodeBarcodeScanner( onScannedCallback: (String value) { - // debugPrint("Scan value vase64: '${utf8.decode(base64.decode(value))}'"); setScannedValue(value); }, ); @@ -45,7 +43,7 @@ class _MyAppState extends State { Expanded( child: Center( child: Text( - _scanValue ?? 'none', + "Scan value: ${_scanValue ?? 'none'}", style: const TextStyle(fontSize: 30), ), ), diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index 73a03ee..4a57242 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -18,8 +18,8 @@ void main() { // Verify that platform version is retrieved. expect( find.byWidgetPredicate( - (Widget widget) => widget is Text && - widget.data!.startsWith('Running on:'), + (Widget widget) => + widget is Text && widget.data!.startsWith('Running on:'), ), findsOneWidget, ); diff --git a/lib/qrcode_barcode_scanner.dart b/lib/qrcode_barcode_scanner.dart index e986190..6773260 100644 --- a/lib/qrcode_barcode_scanner.dart +++ b/lib/qrcode_barcode_scanner.dart @@ -56,7 +56,7 @@ class QrcodeBarcodeScanner { _actionHandler.executeDelayed(() { final String scannedCode = _pressedKeys.isNotEmpty ? _pressedKeys.join() : ""; - onScannedCallback(scannedCode); + onScannedCallback(scannedCode.trim()); _pressedKeys.clear(); }); } @@ -71,7 +71,7 @@ class QrcodeBarcodeScanner { (List.of(event.character?.codeUnits ?? []) ..removeWhere((element) => element == 0)) .isNotEmpty) { - _controller.add(event.character?.trim() ?? ""); + _controller.add(event.character ?? ""); return true; } return false; diff --git a/test/qrcode_barcode_scanner_method_channel_test.dart b/test/qrcode_barcode_scanner_method_channel_test.dart index ad2b259..a2903fe 100644 --- a/test/qrcode_barcode_scanner_method_channel_test.dart +++ b/test/qrcode_barcode_scanner_method_channel_test.dart @@ -5,11 +5,13 @@ import 'package:qrcode_barcode_scanner/qrcode_barcode_scanner_method_channel.dar void main() { TestWidgetsFlutterBinding.ensureInitialized(); - MethodChannelQrcodeBarcodeScanner platform = MethodChannelQrcodeBarcodeScanner(); + MethodChannelQrcodeBarcodeScanner platform = + MethodChannelQrcodeBarcodeScanner(); const MethodChannel channel = MethodChannel('qrcode_barcode_scanner'); setUp(() { - TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler( + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler( channel, (MethodCall methodCall) async { return '42'; @@ -18,7 +20,8 @@ void main() { }); tearDown(() { - TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(channel, null); + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(channel, null); }); test('getPlatformVersion', () async {