mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-31 21:35:42 +00:00 
			
		
		
		
	Using new qr code scanner - qr_code_scanner
This commit is contained in:
		| @@ -23,6 +23,7 @@ if (flutterVersionName == null) { | ||||
|  | ||||
| apply plugin: 'com.android.application' | ||||
| apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" | ||||
| apply plugin: 'kotlin-android' | ||||
|  | ||||
| android { | ||||
|     compileSdkVersion 28 | ||||
| @@ -38,7 +39,7 @@ android { | ||||
|     defaultConfig { | ||||
|         // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). | ||||
|         applicationId "inventree.inventree_app" | ||||
|         minSdkVersion 21 | ||||
|         minSdkVersion 25 | ||||
|         targetSdkVersion 29 | ||||
|         versionCode flutterVersionCode.toInteger() | ||||
|         versionName flutterVersionName | ||||
| @@ -65,4 +66,5 @@ dependencies { | ||||
|     androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||||
|     androidTestImplementation 'com.android.support:multidex:1.0.0' | ||||
|     implementation 'androidx.appcompat:appcompat:1.0.0' | ||||
|     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||||
| } | ||||
|   | ||||
| @@ -30,4 +30,8 @@ | ||||
|             </intent-filter> | ||||
|         </activity> | ||||
|     </application> | ||||
|  | ||||
|     <uses-permission android:name="android.permission.INTERNET"/> | ||||
|     <uses-permission android:name="android.permission.CAMERA"/> | ||||
|     <uses-permission android:name="android.permission.MICROPHONE"/> | ||||
| </manifest> | ||||
| @@ -4,4 +4,6 @@ | ||||
|          to allow setting breakpoints, to provide hot reload, etc. | ||||
|     --> | ||||
|     <uses-permission android:name="android.permission.INTERNET"/> | ||||
|     <uses-permission android:name="android.permission.CAMERA"/> | ||||
|     <uses-permission android:name="android.permission.MICROPHONE"/> | ||||
| </manifest> | ||||
|   | ||||
| @@ -1,4 +1,7 @@ | ||||
| buildscript { | ||||
|  | ||||
|     ext.kotlin_version = '1.3.61' | ||||
|  | ||||
|     repositories { | ||||
|         google() | ||||
|         jcenter() | ||||
| @@ -6,6 +9,7 @@ buildscript { | ||||
|  | ||||
|     dependencies { | ||||
|         classpath 'com.android.tools.build:gradle:3.2.1' | ||||
|         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -5,6 +5,7 @@ export "FLUTTER_APPLICATION_PATH=C:\inventree-app" | ||||
| export "FLUTTER_TARGET=lib\main.dart" | ||||
| export "FLUTTER_BUILD_DIR=build" | ||||
| export "SYMROOT=${SOURCE_ROOT}/../build\ios" | ||||
| export "OTHER_LDFLAGS=$(inherited) -framework Flutter" | ||||
| export "FLUTTER_FRAMEWORK_DIR=C:\flutter\bin\cache\artifacts\engine\ios" | ||||
| export "FLUTTER_BUILD_NAME=1.0.0" | ||||
| export "FLUTTER_BUILD_NUMBER=1" | ||||
|   | ||||
							
								
								
									
										243
									
								
								lib/barcode.dart
									
									
									
									
									
								
							
							
						
						
									
										243
									
								
								lib/barcode.dart
									
									
									
									
									
								
							| @@ -3,6 +3,10 @@ import 'package:flutter/cupertino.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| //import 'package:qr_utils/qr_utils.dart'; | ||||
| //import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart'; | ||||
| //import 'package:barcode_scan/barcode_scan.dart'; | ||||
|  | ||||
| import 'package:qr_code_scanner/qr_code_scanner.dart'; | ||||
|  | ||||
| import 'package:InvenTree/inventree/stock.dart'; | ||||
| import 'package:InvenTree/inventree/part.dart'; | ||||
| @@ -16,86 +20,179 @@ import 'package:InvenTree/widget/stock_detail.dart'; | ||||
|  | ||||
| import 'dart:convert'; | ||||
|  | ||||
|  | ||||
| class InvenTreeQRView extends StatefulWidget { | ||||
|  | ||||
|   InvenTreeQRView({Key key}) : super(key: key); | ||||
|  | ||||
|   @override | ||||
|   State<StatefulWidget> createState() => _QRViewState(); | ||||
| } | ||||
|  | ||||
|  | ||||
| class _QRViewState extends State<InvenTreeQRView> { | ||||
|  | ||||
|   QRViewController _controller; | ||||
|  | ||||
|   BuildContext context; | ||||
|  | ||||
|   _QRViewState() : super(); | ||||
|  | ||||
|   final GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); | ||||
|  | ||||
|   Future<void> processBarcode(String barcode) async { | ||||
|     if (barcode == null || barcode.isEmpty) { | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     print("Scanned: ${barcode}"); | ||||
|     showProgressDialog(context, "Querying server", "Sending barcode data to server"); | ||||
|  | ||||
|     InvenTreeAPI().post("barcode/", body: {"barcode": barcode}).then((var response) { | ||||
|       hideProgressDialog(context); | ||||
|  | ||||
|       print("Response:"); | ||||
|       print(response.body); | ||||
|     }).timeout( | ||||
|         Duration(seconds: 5) | ||||
|     ).catchError((error) { | ||||
|       hideProgressDialog(context); | ||||
|       showErrorDialog(context, "Error", error.toString()); | ||||
|       return; | ||||
|     }); | ||||
|  | ||||
|   } | ||||
|  | ||||
|   void _onViewCreated(QRViewController controller) { | ||||
|     _controller = controller; | ||||
|     controller.scannedDataStream.listen((scandata) { | ||||
|       processBarcode(scandata); | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void dispose() { | ||||
|     _controller.dispose(); | ||||
|     super.dispose(); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|  | ||||
|     // Save the context for later on! | ||||
|     this.context = context; | ||||
|  | ||||
|     return Scaffold( | ||||
|       body: Column( | ||||
|         children: <Widget>[ | ||||
|           Expanded( | ||||
|             flex: 4, | ||||
|             child: QRView( | ||||
|               key: qrKey, | ||||
|               onQRViewCreated: _onViewCreated, | ||||
|               overlay: QrScannerOverlayShape( | ||||
|                 borderColor: Colors.red, | ||||
|                 borderRadius: 10, | ||||
|                 borderLength: 30, | ||||
|                 borderWidth: 10, | ||||
|                 cutOutSize: 300, | ||||
|               ), | ||||
|             ) | ||||
|           ) | ||||
|         ], | ||||
|       ) | ||||
|     ); | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| Future<void> scanQrCode(BuildContext context) async { | ||||
|  | ||||
|   Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeQRView())); | ||||
|  | ||||
|   return; | ||||
|   /* | ||||
|   QrUtils.scanQR.then((String barcode) { | ||||
|   print("Scanning"); | ||||
|   String barcode = await FlutterBarcodeScanner.scanBarcode("#F00", "Cancel", false, ScanMode.DEFAULT); | ||||
|   print("and, DONE"); | ||||
|   if (barcode == null || barcode.isEmpty) { | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|     print("Scanned: $barcode"); | ||||
|   print("Scanned: $barcode"); | ||||
|  | ||||
|     showProgressDialog(context, "Querying Server", "Sending barcode data to server"); | ||||
|  | ||||
|     /* | ||||
|      * POST the scanned barcode data to the server. | ||||
|      * It is the responsibility of the server to validate and sanitize the barcode data, | ||||
|      * and return a "common" response that we know how to deal with. | ||||
|      */ | ||||
|     InvenTreeAPI().post("barcode/", body: {"barcode": barcode}).then((var response) { | ||||
|  | ||||
|       hideProgressDialog(context); | ||||
|  | ||||
|       if (response.statusCode != 200) { | ||||
|         showDialog( | ||||
|           context: context, | ||||
|           child: new SimpleDialog( | ||||
|             title: Text("Server Error"), | ||||
|             children: <Widget>[ | ||||
|               ListTile( | ||||
|                 title: Text("Error ${response.statusCode}"), | ||||
|                 subtitle: Text("${response.body.toString().split("\n").first}"), | ||||
|               ) | ||||
|             ], | ||||
|           ), | ||||
|         ); | ||||
|  | ||||
|         return; | ||||
|       } | ||||
|  | ||||
|       final Map<String, dynamic> body = json.decode(response.body); | ||||
|  | ||||
|       // TODO - Handle potential error decoding response | ||||
|  | ||||
|       print("Barcode response:"); | ||||
|       print(body.toString()); | ||||
|  | ||||
|       if (body.containsKey('error')) { | ||||
|         showDialog( | ||||
|           context: context, | ||||
|           child: new SimpleDialog( | ||||
|             title: Text("Barcode Error"), | ||||
|             children: <Widget>[ | ||||
|               ListTile( | ||||
|                 title: Text("${body['error']}"), | ||||
|                 subtitle: Text("Plugin: ${body['plugin'] ?? '<no plugin information>'}"), | ||||
|               ) | ||||
|             ], | ||||
|           ) | ||||
|         ); | ||||
|       } else if (body.containsKey('success')) { | ||||
|         // Decode the barcode! | ||||
|         // Ideally, the server has returned unto us something sensible... | ||||
|         _handleBarcode(context, body); | ||||
|       } else { | ||||
|         showDialog( | ||||
|           context: context, | ||||
|           child: new SimpleDialog( | ||||
|             title: Text("Unknown response"), | ||||
|             children: <Widget>[ | ||||
|               ListTile( | ||||
|                 title: Text("Response data"), | ||||
|                 subtitle: Text("${body.toString()}"), | ||||
|               ) | ||||
|             ], | ||||
|           ) | ||||
|         ); | ||||
|       } | ||||
|  | ||||
|       print("body: ${body.toString()}"); | ||||
|  | ||||
|     }); | ||||
|   }); | ||||
|   showProgressDialog(context, "Querying Server", "Sending barcode data to server"); | ||||
|   */ | ||||
|  | ||||
|   String barcode = null; | ||||
|   /* | ||||
|    * POST the scanned barcode data to the server. | ||||
|    * It is the responsibility of the server to validate and sanitize the barcode data, | ||||
|    * and return a "common" response that we know how to deal with. | ||||
|    */ | ||||
|   InvenTreeAPI().post("barcode/", body: {"barcode": barcode}).then((var response) { | ||||
|  | ||||
|     hideProgressDialog(context); | ||||
|  | ||||
|     if (response.statusCode != 200) { | ||||
|       showDialog( | ||||
|         context: context, | ||||
|         child: new SimpleDialog( | ||||
|           title: Text("Server Error"), | ||||
|           children: <Widget>[ | ||||
|             ListTile( | ||||
|               title: Text("Error ${response.statusCode}"), | ||||
|               subtitle: Text("${response.body.toString().split("\n").first}"), | ||||
|             ) | ||||
|           ], | ||||
|         ), | ||||
|       ); | ||||
|  | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     final Map<String, dynamic> body = json.decode(response.body); | ||||
|  | ||||
|     // TODO - Handle potential error decoding response | ||||
|  | ||||
|     print("Barcode response:"); | ||||
|     print(body.toString()); | ||||
|  | ||||
|     if (body.containsKey('error')) { | ||||
|       showDialog( | ||||
|         context: context, | ||||
|         child: new SimpleDialog( | ||||
|           title: Text("Barcode Error"), | ||||
|           children: <Widget>[ | ||||
|             ListTile( | ||||
|               title: Text("${body['error']}"), | ||||
|               subtitle: Text("Plugin: ${body['plugin'] ?? '<no plugin information>'}"), | ||||
|             ) | ||||
|           ], | ||||
|         ) | ||||
|       ); | ||||
|     } else if (body.containsKey('success')) { | ||||
|       // Decode the barcode! | ||||
|       // Ideally, the server has returned unto us something sensible... | ||||
|       _handleBarcode(context, body); | ||||
|     } else { | ||||
|       showDialog( | ||||
|         context: context, | ||||
|         child: new SimpleDialog( | ||||
|           title: Text("Unknown response"), | ||||
|           children: <Widget>[ | ||||
|             ListTile( | ||||
|               title: Text("Response data"), | ||||
|               subtitle: Text("${body.toString()}"), | ||||
|             ) | ||||
|           ], | ||||
|         ) | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|     print("body: ${body.toString()}"); | ||||
|  | ||||
|   }); | ||||
| } | ||||
|  | ||||
| void _handleBarcode(BuildContext context, Map<String, dynamic> data) { | ||||
|   | ||||
							
								
								
									
										35
									
								
								pubspec.lock
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								pubspec.lock
									
									
									
									
									
								
							| @@ -7,28 +7,28 @@ packages: | ||||
|       name: archive | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "2.0.11" | ||||
|     version: "2.0.13" | ||||
|   args: | ||||
|     dependency: transitive | ||||
|     description: | ||||
|       name: args | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "1.5.2" | ||||
|     version: "1.6.0" | ||||
|   async: | ||||
|     dependency: transitive | ||||
|     description: | ||||
|       name: async | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "2.4.0" | ||||
|     version: "2.4.1" | ||||
|   boolean_selector: | ||||
|     dependency: transitive | ||||
|     description: | ||||
|       name: boolean_selector | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "1.0.5" | ||||
|     version: "2.0.0" | ||||
|   camera: | ||||
|     dependency: "direct main" | ||||
|     description: | ||||
| @@ -42,14 +42,14 @@ packages: | ||||
|       name: charcode | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "1.1.2" | ||||
|     version: "1.1.3" | ||||
|   collection: | ||||
|     dependency: transitive | ||||
|     description: | ||||
|       name: collection | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "1.14.11" | ||||
|     version: "1.14.12" | ||||
|   convert: | ||||
|     dependency: transitive | ||||
|     description: | ||||
| @@ -63,7 +63,7 @@ packages: | ||||
|       name: crypto | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "2.1.3" | ||||
|     version: "2.1.4" | ||||
|   cupertino_icons: | ||||
|     dependency: "direct main" | ||||
|     description: | ||||
| @@ -162,7 +162,7 @@ packages: | ||||
|       name: image | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "2.1.4" | ||||
|     version: "2.1.12" | ||||
|   image_picker: | ||||
|     dependency: "direct main" | ||||
|     description: | ||||
| @@ -246,7 +246,7 @@ packages: | ||||
|       name: pedantic | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "1.8.0+1" | ||||
|     version: "1.9.0" | ||||
|   petitparser: | ||||
|     dependency: transitive | ||||
|     description: | ||||
| @@ -275,13 +275,20 @@ packages: | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "5.2.0" | ||||
|   qr_code_scanner: | ||||
|     dependency: "direct main" | ||||
|     description: | ||||
|       name: qr_code_scanner | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "0.0.13" | ||||
|   quiver: | ||||
|     dependency: transitive | ||||
|     description: | ||||
|       name: quiver | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "2.0.5" | ||||
|     version: "2.1.3" | ||||
|   sentry: | ||||
|     dependency: "direct main" | ||||
|     description: | ||||
| @@ -328,7 +335,7 @@ packages: | ||||
|       name: source_span | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "1.5.5" | ||||
|     version: "1.7.0" | ||||
|   stack_trace: | ||||
|     dependency: transitive | ||||
|     description: | ||||
| @@ -363,7 +370,7 @@ packages: | ||||
|       name: test_api | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "0.2.11" | ||||
|     version: "0.2.15" | ||||
|   typed_data: | ||||
|     dependency: transitive | ||||
|     description: | ||||
| @@ -391,7 +398,7 @@ packages: | ||||
|       name: xml | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "3.5.0" | ||||
|     version: "3.6.1" | ||||
|   yaml: | ||||
|     dependency: transitive | ||||
|     description: | ||||
| @@ -400,5 +407,5 @@ packages: | ||||
|     source: hosted | ||||
|     version: "2.2.1" | ||||
| sdks: | ||||
|   dart: ">=2.4.0 <3.0.0" | ||||
|   dart: ">=2.6.0 <3.0.0" | ||||
|   flutter: ">=1.12.13+hotfix.5 <2.0.0" | ||||
|   | ||||
							
								
								
									
										12
									
								
								pubspec.yaml
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								pubspec.yaml
									
									
									
									
									
								
							| @@ -22,20 +22,20 @@ dependencies: | ||||
|  | ||||
|   # The following adds the Cupertino Icons font to your application. | ||||
|   # Use with the CupertinoIcons class for iOS style icons. | ||||
|   cupertino_icons: ^0.1.2 | ||||
|   cupertino_icons: ^0.1.3 | ||||
|   http: ^0.12.1 | ||||
|   shared_preferences: ^0.5.3+1 | ||||
|   shared_preferences: ^0.5.7 | ||||
|  | ||||
|   flutter_advanced_networkimage: ^0.7.0   # Pull image from network or cache | ||||
|   preferences: ^5.1.0                     # Persistent settings storage | ||||
|   #qr_utils: ^0.1.4                        # Barcode / QR-code support | ||||
|   package_info: ^0.4.0+16                 # App information introspection | ||||
|   preferences: ^5.2.0                     # Persistent settings storage | ||||
|   #barcode_scan: ^3.0.1                    # Barcode / QR code scanning | ||||
|   qr_code_scanner: ^0.0.13 | ||||
|   package_info: ^0.4.0                    # App information introspection | ||||
|   font_awesome_flutter: ^8.8.1            # FontAwesome icon set | ||||
|   flutter_speed_dial: ^1.2.5              # FAB menu elements | ||||
|   sentry: ^3.0.1                          # Error reporting | ||||
|   flutter_typeahead: ^1.8.1               # Auto-complete input field | ||||
|   image_picker: ^0.6.6                    # Select or take photos | ||||
|   #flutter_form_builder: | ||||
|  | ||||
|   camera: | ||||
|   path_provider: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user