bar code scanner is replaced

This commit is contained in:
artchiee
2023-06-19 18:33:29 +01:00
parent 40029983d6
commit 5ec43b65ef
7 changed files with 549 additions and 204 deletions

26
.vscode/settings.json vendored
View File

@@ -1,4 +1,24 @@
{
"dart.lineLength": 100,
"diffEditor.ignoreTrimWhitespace": true,
}
"dart.lineLength": 100,
"diffEditor.ignoreTrimWhitespace": true,
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#55b9e8",
"activityBar.background": "#55b9e8",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#c51b8e",
"activityBarBadge.foreground": "#e7e7e7",
"commandCenter.border": "#15202b99",
"sash.hoverBorder": "#55b9e8",
"statusBar.background": "#28a7e2",
"statusBar.foreground": "#15202b",
"statusBarItem.hoverBackground": "#1a89bd",
"statusBarItem.remoteBackground": "#28a7e2",
"statusBarItem.remoteForeground": "#15202b",
"titleBar.activeBackground": "#28a7e2",
"titleBar.activeForeground": "#15202b",
"titleBar.inactiveBackground": "#28a7e299",
"titleBar.inactiveForeground": "#15202b99"
},
"peacock.color": "#28a7e2"
}

View File

@@ -82,4 +82,4 @@ packages:
source: hosted
version: "1.3.1"
sdks:
dart: ">=2.18.5 <3.0.0"
dart: ">=2.18.5 <4.0.0"

View File

@@ -50,8 +50,12 @@ import 'package:wger/theme/theme.dart';
import 'package:wger/widgets/core/about.dart';
import 'providers/auth.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_zxing/flutter_zxing.dart';
void main() {
zx.setLogEnabled(kDebugMode);
// Needs to be called before runApp
WidgetsFlutterBinding.ensureInitialized();

View File

@@ -16,11 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
//import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
import 'package:wger/helpers/consts.dart';
import 'package:wger/helpers/platform.dart';
@@ -28,11 +31,33 @@ import 'package:wger/helpers/ui.dart';
import 'package:wger/providers/nutrition.dart';
import 'package:wger/widgets/core/core.dart';
import 'package:flutter_zxing/flutter_zxing.dart';
class ScanReader extends StatelessWidget {
String? scannedr;
@override
Widget build(BuildContext context) {
return Scaffold(
body: ReaderWidget(
onScan: (result) {
debugPrint('Reader widget res : => ');
scannedr = result.text;
debugPrint(scannedr);
Navigator.pop(context, scannedr);
},
),
);
}
}
class IngredientTypeahead extends StatefulWidget {
final TextEditingController _ingredientController;
final TextEditingController _ingredientIdController;
String? barcode = '';
Code? result;
late final bool? test;
final bool showScanner;
@@ -48,29 +73,25 @@ class IngredientTypeahead extends StatefulWidget {
_IngredientTypeaheadState createState() => _IngredientTypeaheadState();
}
Future<String> scanBarcode(BuildContext context) async {
String barcode;
try {
barcode = await FlutterBarcodeScanner.scanBarcode(
'#ff6666',
AppLocalizations.of(context).close,
true,
ScanMode.BARCODE,
);
if (barcode.compareTo('-1') == 0) {
return '';
}
} on PlatformException {
return '';
}
return barcode;
}
class _IngredientTypeaheadState extends State<IngredientTypeahead> {
var _searchEnglish = true;
Future<String> _readerscan(BuildContext context) async {
String barcode;
try {
barcode =
await Navigator.of(context).push(MaterialPageRoute(builder: (context) => ScanReader()));
if (barcode.compareTo('-1') == 0) {
return '';
}
} on PlatformException {
return '';
}
return barcode;
}
@override
Widget build(BuildContext context) {
return Column(
@@ -136,7 +157,8 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
onPressed: () async {
try {
if (!widget.test!) {
widget.barcode = await scanBarcode(context);
// using navigation to call Reader Widget and return context(scan result)
widget.barcode = await _readerscan(context);
}
if (widget.barcode!.isNotEmpty) {
@@ -194,6 +216,7 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
}
}
} catch (e) {
debugPrint('scanner did not fire!! ');
showErrorDialog(e, context);
}
},

View File

@@ -7,6 +7,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST
flutter_zxing
)
set(PLUGIN_BUNDLED_LIBRARIES)

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@ description: Self hosted workout, nutrition and weight manager.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
publish_to: "none" # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
@@ -24,7 +24,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.5.4+31
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
@@ -58,6 +58,7 @@ dependencies:
carousel_slider: ^4.2.1
multi_select_flutter: ^4.1.3
flutter_svg: ^2.0.5
flutter_zxing: ^1.1.2
dev_dependencies:
flutter_test:
@@ -82,13 +83,11 @@ flutter_icons:
generate: true
image_path: "assets/images/logo.png"
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.