Skip to content

Commit

Permalink
Fix handle space in scan value
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
FrenkyDema committed Mar 21, 2024
1 parent 2946ec4 commit 3dca2d1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions example/integration_test/plugin_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class _MyAppState extends State<MyApp> {
String? _scanValue;

void setScannedValue(String value) {
debugPrint("$value ${value.length}");
setState(() {
_scanValue = value;
});
Expand All @@ -27,7 +26,6 @@ class _MyAppState extends State<MyApp> {
super.initState();
QrcodeBarcodeScanner(
onScannedCallback: (String value) {
// debugPrint("Scan value vase64: '${utf8.decode(base64.decode(value))}'");
setScannedValue(value);
},
);
Expand All @@ -45,7 +43,7 @@ class _MyAppState extends State<MyApp> {
Expanded(
child: Center(
child: Text(
_scanValue ?? 'none',
"Scan value: ${_scanValue ?? 'none'}",
style: const TextStyle(fontSize: 30),
),
),
Expand Down
4 changes: 2 additions & 2 deletions example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
4 changes: 2 additions & 2 deletions lib/qrcode_barcode_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class QrcodeBarcodeScanner {
_actionHandler.executeDelayed(() {
final String scannedCode =
_pressedKeys.isNotEmpty ? _pressedKeys.join() : "";
onScannedCallback(scannedCode);
onScannedCallback(scannedCode.trim());
_pressedKeys.clear();
});
}
Expand All @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions test/qrcode_barcode_scanner_method_channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -18,7 +20,8 @@ void main() {
});

tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(channel, null);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, null);
});

test('getPlatformVersion', () async {
Expand Down

0 comments on commit 3dca2d1

Please sign in to comment.