Skip to content

Commit 72e9f4b

Browse files
committed
null check fixed whene poping back from scanner
1 parent c0bc830 commit 72e9f4b

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

lib/widgets/nutrition/widgets.dart

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
*/
1818

1919
import 'dart:developer';
20+
import 'dart:io';
2021

2122
import 'package:flutter/material.dart';
2223
import 'package:flutter/services.dart';
23-
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
24+
//import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
2425
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2526
import 'package:flutter_typeahead/flutter_typeahead.dart';
26-
//import 'package:font_awesome_flutter/font_awesome_flutter.dart';
27+
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
2728
import 'package:provider/provider.dart';
2829
import 'package:wger/helpers/consts.dart';
2930
import 'package:wger/helpers/platform.dart';
@@ -33,30 +34,28 @@ import 'package:wger/widgets/core/core.dart';
3334

3435
import 'package:flutter_zxing/flutter_zxing.dart';
3536

37+
3638
class ScanReader extends StatelessWidget {
3739
String? scannedr;
3840

3941
@override
40-
Widget build(BuildContext context) {
41-
return Scaffold(
42-
body: ReaderWidget(
43-
onScan: (result) {
44-
debugPrint('Reader widget res : => ');
45-
scannedr = result.text;
46-
debugPrint(scannedr);
47-
Navigator.pop(context, scannedr);
48-
},
49-
),
50-
);
51-
}
42+
Widget build(BuildContext context) => Scaffold(
43+
body: ReaderWidget(
44+
onScan: (result) {
45+
scannedr = result.text;
46+
Navigator.pop(context, scannedr);
47+
},
48+
),
49+
);
50+
5251
}
5352

5453
class IngredientTypeahead extends StatefulWidget {
5554
final TextEditingController _ingredientController;
5655
final TextEditingController _ingredientIdController;
5756

5857
String? barcode = '';
59-
Code? result;
58+
//Code? result;
6059

6160
late final bool? test;
6261
final bool showScanner;
@@ -76,20 +75,20 @@ class IngredientTypeahead extends StatefulWidget {
7675
class _IngredientTypeaheadState extends State<IngredientTypeahead> {
7776
var _searchEnglish = true;
7877

79-
Future<String> _readerscan(BuildContext context) async {
80-
String barcode;
78+
Future<String> readerscan(BuildContext context) async {
79+
String scannedcode;
8180
try {
82-
barcode =
81+
scannedcode =
8382
await Navigator.of(context).push(MaterialPageRoute(builder: (context) => ScanReader()));
8483

85-
if (barcode.compareTo('-1') == 0) {
84+
if (scannedcode.compareTo('-1') == 0) {
8685
return '';
8786
}
8887
} on PlatformException {
8988
return '';
9089
}
9190

92-
return barcode;
91+
return scannedcode;
9392
}
9493

9594
@override
@@ -157,8 +156,7 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
157156
onPressed: () async {
158157
try {
159158
if (!widget.test!) {
160-
// using navigation to call Reader Widget and return context(scan result)
161-
widget.barcode = await _readerscan(context);
159+
widget.barcode = await readerscan(context);
162160
}
163161

164162
if (widget.barcode!.isNotEmpty) {
@@ -216,8 +214,10 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
216214
}
217215
}
218216
} catch (e) {
219-
debugPrint('scanner did not fire!! ');
220217
showErrorDialog(e, context);
218+
// Need to pop back since reader scan is a widget
219+
// otherwise returns null when back button is pressed
220+
return Navigator.pop(context);
221221
}
222222
},
223223
icon: Image.asset('assets/images/barcode_scanner_icon.png'),

linux/flutter/generated_plugin_registrant.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66

77
#include "generated_plugin_registrant.h"
88

9+
#include <file_selector_linux/file_selector_plugin.h>
910
#include <url_launcher_linux/url_launcher_plugin.h>
1011

1112
void fl_register_plugins(FlPluginRegistry* registry) {
13+
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
14+
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
15+
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
1216
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
1317
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
1418
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);

linux/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
list(APPEND FLUTTER_PLUGIN_LIST
6+
file_selector_linux
67
url_launcher_linux
78
)
89

macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import FlutterMacOS
66
import Foundation
77

8+
import file_selector_macos
89
import package_info_plus
910
import rive_common
1011
import shared_preferences_foundation
1112
import url_launcher_macos
1213

1314
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
15+
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
1416
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
1517
RivePlugin.register(with: registry.registrar(forPlugin: "RivePlugin"))
1618
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))

0 commit comments

Comments
 (0)