2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 05:26:47 +00:00

Using new qr code scanner - qr_code_scanner

This commit is contained in:
Oliver Walters 2020-05-26 23:02:19 +10:00
parent aad616aea1
commit a4390d16d9
8 changed files with 211 additions and 94 deletions

View File

@ -23,6 +23,7 @@ if (flutterVersionName == null) {
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'kotlin-android'
android { android {
compileSdkVersion 28 compileSdkVersion 28
@ -38,7 +39,7 @@ android {
defaultConfig { defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "inventree.inventree_app" applicationId "inventree.inventree_app"
minSdkVersion 21 minSdkVersion 25
targetSdkVersion 29 targetSdkVersion 29
versionCode flutterVersionCode.toInteger() versionCode flutterVersionCode.toInteger()
versionName flutterVersionName versionName flutterVersionName
@ -65,4 +66,5 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support:multidex:1.0.0' androidTestImplementation 'com.android.support:multidex:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0' implementation 'androidx.appcompat:appcompat:1.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
} }

View File

@ -30,4 +30,8 @@
</intent-filter> </intent-filter>
</activity> </activity>
</application> </application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.MICROPHONE"/>
</manifest> </manifest>

View File

@ -4,4 +4,6 @@
to allow setting breakpoints, to provide hot reload, etc. to allow setting breakpoints, to provide hot reload, etc.
--> -->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.MICROPHONE"/>
</manifest> </manifest>

View File

@ -1,4 +1,7 @@
buildscript { buildscript {
ext.kotlin_version = '1.3.61'
repositories { repositories {
google() google()
jcenter() jcenter()
@ -6,6 +9,7 @@ buildscript {
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
} }
} }

View File

@ -5,6 +5,7 @@ export "FLUTTER_APPLICATION_PATH=C:\inventree-app"
export "FLUTTER_TARGET=lib\main.dart" export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build" export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build\ios" 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_FRAMEWORK_DIR=C:\flutter\bin\cache\artifacts\engine\ios"
export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1" export "FLUTTER_BUILD_NUMBER=1"

View File

@ -3,6 +3,10 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
//import 'package:qr_utils/qr_utils.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/stock.dart';
import 'package:InvenTree/inventree/part.dart'; import 'package:InvenTree/inventree/part.dart';
@ -16,16 +20,111 @@ import 'package:InvenTree/widget/stock_detail.dart';
import 'dart:convert'; 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 { Future<void> scanQrCode(BuildContext context) async {
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeQRView()));
return; 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"); showProgressDialog(context, "Querying Server", "Sending barcode data to server");
*/
String barcode = null;
/* /*
* POST the scanned barcode data to the server. * POST the scanned barcode data to the server.
* It is the responsibility of the server to validate and sanitize the barcode data, * It is the responsibility of the server to validate and sanitize the barcode data,
@ -94,8 +193,6 @@ Future<void> scanQrCode(BuildContext context) async {
print("body: ${body.toString()}"); print("body: ${body.toString()}");
}); });
});
*/
} }
void _handleBarcode(BuildContext context, Map<String, dynamic> data) { void _handleBarcode(BuildContext context, Map<String, dynamic> data) {

View File

@ -7,28 +7,28 @@ packages:
name: archive name: archive
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.11" version: "2.0.13"
args: args:
dependency: transitive dependency: transitive
description: description:
name: args name: args
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.5.2" version: "1.6.0"
async: async:
dependency: transitive dependency: transitive
description: description:
name: async name: async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.4.0" version: "2.4.1"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
name: boolean_selector name: boolean_selector
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.5" version: "2.0.0"
camera: camera:
dependency: "direct main" dependency: "direct main"
description: description:
@ -42,14 +42,14 @@ packages:
name: charcode name: charcode
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.2" version: "1.1.3"
collection: collection:
dependency: transitive dependency: transitive
description: description:
name: collection name: collection
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.14.11" version: "1.14.12"
convert: convert:
dependency: transitive dependency: transitive
description: description:
@ -63,7 +63,7 @@ packages:
name: crypto name: crypto
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.3" version: "2.1.4"
cupertino_icons: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
@ -162,7 +162,7 @@ packages:
name: image name: image
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.4" version: "2.1.12"
image_picker: image_picker:
dependency: "direct main" dependency: "direct main"
description: description:
@ -246,7 +246,7 @@ packages:
name: pedantic name: pedantic
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0+1" version: "1.9.0"
petitparser: petitparser:
dependency: transitive dependency: transitive
description: description:
@ -275,13 +275,20 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "5.2.0" 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: quiver:
dependency: transitive dependency: transitive
description: description:
name: quiver name: quiver
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.5" version: "2.1.3"
sentry: sentry:
dependency: "direct main" dependency: "direct main"
description: description:
@ -328,7 +335,7 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.5.5" version: "1.7.0"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
@ -363,7 +370,7 @@ packages:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.11" version: "0.2.15"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
@ -391,7 +398,7 @@ packages:
name: xml name: xml
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.5.0" version: "3.6.1"
yaml: yaml:
dependency: transitive dependency: transitive
description: description:
@ -400,5 +407,5 @@ packages:
source: hosted source: hosted
version: "2.2.1" version: "2.2.1"
sdks: sdks:
dart: ">=2.4.0 <3.0.0" dart: ">=2.6.0 <3.0.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0" flutter: ">=1.12.13+hotfix.5 <2.0.0"

View File

@ -22,20 +22,20 @@ dependencies:
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2 cupertino_icons: ^0.1.3
http: ^0.12.1 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 flutter_advanced_networkimage: ^0.7.0 # Pull image from network or cache
preferences: ^5.1.0 # Persistent settings storage preferences: ^5.2.0 # Persistent settings storage
#qr_utils: ^0.1.4 # Barcode / QR-code support #barcode_scan: ^3.0.1 # Barcode / QR code scanning
package_info: ^0.4.0+16 # App information introspection qr_code_scanner: ^0.0.13
package_info: ^0.4.0 # App information introspection
font_awesome_flutter: ^8.8.1 # FontAwesome icon set font_awesome_flutter: ^8.8.1 # FontAwesome icon set
flutter_speed_dial: ^1.2.5 # FAB menu elements flutter_speed_dial: ^1.2.5 # FAB menu elements
sentry: ^3.0.1 # Error reporting sentry: ^3.0.1 # Error reporting
flutter_typeahead: ^1.8.1 # Auto-complete input field flutter_typeahead: ^1.8.1 # Auto-complete input field
image_picker: ^0.6.6 # Select or take photos image_picker: ^0.6.6 # Select or take photos
#flutter_form_builder:
camera: camera:
path_provider: path_provider: