Browse Source

scan barcode screen

master
daivph 5 years ago
parent
commit
67b6794d77
12 changed files with 174 additions and 19 deletions
  1. +1
    -1
      android/app/build.gradle
  2. +1
    -0
      android/app/src/main/AndroidManifest.xml
  3. +1
    -1
      android/build.gradle
  4. +17
    -0
      ios/Podfile.lock
  5. +22
    -13
      ios/Runner.xcodeproj/project.pbxproj
  6. +3
    -0
      ios/Runner/Info.plist
  7. +3
    -2
      lib/presentation/custom_widgets/widget_toast.dart
  8. +98
    -0
      lib/presentation/screens/scan_barcode/sc_scan_barcode.dart
  9. +6
    -2
      lib/presentation/screens/slide_menu/home_drawer.dart
  10. +7
    -0
      lib/presentation/screens/slide_menu/navigation_home_screen.dart
  11. +14
    -0
      pubspec.lock
  12. +1
    -0
      pubspec.yaml

+ 1
- 1
android/app/build.gradle View File

@@ -39,7 +39,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.farm_tpf"
minSdkVersion 16
minSdkVersion 18
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName

+ 1
- 0
android/app/src/main/AndroidManifest.xml View File

@@ -6,6 +6,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="farm_tpf"

+ 1
- 1
android/build.gradle View File

@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()

+ 17
- 0
ios/Podfile.lock View File

@@ -1,5 +1,10 @@
PODS:
- barcode_scan (0.0.1):
- Flutter
- MTBBarcodeScanner
- SwiftProtobuf
- Flutter (1.0.0)
- MTBBarcodeScanner (5.0.11)
- path_provider_linux (0.0.1):
- Flutter
- shared_preferences (0.0.1):
@@ -10,8 +15,10 @@ PODS:
- Flutter
- shared_preferences_web (0.0.1):
- Flutter
- SwiftProtobuf (1.11.0)

DEPENDENCIES:
- barcode_scan (from `.symlinks/plugins/barcode_scan/ios`)
- Flutter (from `Flutter`)
- path_provider_linux (from `.symlinks/plugins/path_provider_linux/ios`)
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
@@ -19,7 +26,14 @@ DEPENDENCIES:
- shared_preferences_macos (from `.symlinks/plugins/shared_preferences_macos/ios`)
- shared_preferences_web (from `.symlinks/plugins/shared_preferences_web/ios`)

SPEC REPOS:
trunk:
- MTBBarcodeScanner
- SwiftProtobuf

EXTERNAL SOURCES:
barcode_scan:
:path: ".symlinks/plugins/barcode_scan/ios"
Flutter:
:path: Flutter
path_provider_linux:
@@ -34,12 +48,15 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/shared_preferences_web/ios"

SPEC CHECKSUMS:
barcode_scan: a5c27959edfafaa0c771905bad0b29d6d39e4479
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
MTBBarcodeScanner: f453b33c4b7dfe545d8c6484ed744d55671788cb
path_provider_linux: 4d630dc393e1f20364f3e3b4a2ff41d9674a84e4
shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d
shared_preferences_linux: afefbfe8d921e207f01ede8b60373d9e3b566b78
shared_preferences_macos: f3f29b71ccbb56bf40c9dd6396c9acf15e214087
shared_preferences_web: 141cce0c3ed1a1c5bf2a0e44f52d31eeb66e5ea9
SwiftProtobuf: f889fe5772f90ef7d7b8aac352d1fddf39650713

PODFILE CHECKSUM: c34e2287a9ccaa606aeceab922830efb9a6ff69a


+ 22
- 13
ios/Runner.xcodeproj/project.pbxproj View File

@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 50;
objects = {

/* Begin PBXBuildFile section */
@@ -68,7 +68,6 @@
1BA1D19EF353DFCE335E0C1F /* Pods-Runner.release.xcconfig */,
95FEBA268448B96856A798E7 /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
@@ -225,15 +224,12 @@
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../Flutter/Flutter.framework",
"${BUILT_PRODUCTS_DIR}/shared_preferences/shared_preferences.framework",
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/shared_preferences.framework",
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
@@ -368,13 +364,17 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = C3DTD2JH94;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
@@ -489,7 +489,8 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
@@ -502,13 +503,17 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = C3DTD2JH94;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
@@ -529,13 +534,17 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = C3DTD2JH94;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",

+ 3
- 0
ios/Runner/Info.plist View File

@@ -41,5 +41,8 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<!-- Camera Permission -->
<key>NSCameraUsageDescription</key>
<string>Camera permission is required for barcode scanning.</string>
</dict>
</plist>

+ 3
- 2
lib/presentation/custom_widgets/widget_toast.dart View File

@@ -2,7 +2,8 @@ import 'package:flutter/material.dart';

class WidgetToast extends StatelessWidget {
String message;
WidgetToast({@required this.message});
Color color = Colors.greenAccent;
WidgetToast({@required this.message, this.color});

@override
Widget build(BuildContext context) {
@@ -10,7 +11,7 @@ class WidgetToast extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25.0),
color: Colors.greenAccent,
color: color,
),
child: Row(
mainAxisSize: MainAxisSize.min,

+ 98
- 0
lib/presentation/screens/scan_barcode/sc_scan_barcode.dart View File

@@ -0,0 +1,98 @@
import 'dart:io' show Platform;

import 'package:barcode_scan/barcode_scan.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_toast.dart';
import 'package:farm_tpf/presentation/screens/home/home.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';

class ScanBarcodeScreen extends StatefulWidget {
@override
_ScanBarcodeScreenState createState() => _ScanBarcodeScreenState();
}

class _ScanBarcodeScreenState extends State<ScanBarcodeScreen> {
ScanResult scanResult;

var _aspectTolerance = 0.00;
var _selectedCamera = -1;
var _useAutoFocus = true;
var _autoEnableFlash = false;
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
FlutterToast flutterToast;

@override
// ignore: type_annotate_public_apis
initState() {
super.initState();
flutterToast = FlutterToast(context);
scan();
}

@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: Text("Quét mã QR"),
),
body: Center(
child: scanResult == null ? Container() : Text(scanResult?.rawContent),
),
);
}

Future scan() async {
try {
var options = ScanOptions(
strings: {
"cancel": "Huỷ",
"flash_on": "Bật flash",
"flash_off": "Tắt flash",
},
useCamera: _selectedCamera,
autoEnableFlash: _autoEnableFlash,
android: AndroidOptions(
aspectTolerance: _aspectTolerance,
useAutoFocus: _useAutoFocus,
),
);
var result = await BarcodeScanner.scan(options: options);
setState(() {
scanResult = result;
if (1 != 1) {
Navigator.of(context).pop();
Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => HomePage()));
} else {
flutterToast.showToast(
child:
WidgetToast(message: "Mã QR không đúng", color: Colors.red));
Navigator.of(context).pop();
}
});
} on PlatformException catch (e) {
var result = ScanResult(
type: ResultType.Error,
format: BarcodeFormat.unknown,
);

if (e.code == BarcodeScanner.cameraAccessDenied) {
setState(() {
result.rawContent = 'Vui lòng cấp quyền truy cập camera';
});
} else {
result.rawContent = 'Vui lòng cấp quyền truy cập camera.';
}
setState(() {
scanResult = result;
});
flutterToast.showToast(
child: WidgetToast(
message: "Vui lòng cấp quyền truy cập camera.",
color: Colors.red));
Navigator.of(context).pop();
}
}
}

+ 6
- 2
lib/presentation/screens/slide_menu/home_drawer.dart View File

@@ -29,9 +29,13 @@ class _HomeDrawerState extends State<HomeDrawer> {

void setdDrawerListArray() {
drawerList = <DrawerList>[
DrawerList(
index: DrawerIndex.ScanBarcode,
labelName: "Quét mã QR",
icon: Icon(Icons.scanner)),
DrawerList(
index: DrawerIndex.Home,
labelName: 'Trang chủ',
labelName: 'Danh sách lô',
icon: Icon(Icons.home),
),
DrawerList(
@@ -257,7 +261,7 @@ class _HomeDrawerState extends State<HomeDrawer> {
}
}

enum DrawerIndex { Home, Setting }
enum DrawerIndex { ScanBarcode, Home, Setting }

class DrawerList {
DrawerList({

+ 7
- 0
lib/presentation/screens/slide_menu/navigation_home_screen.dart View File

@@ -1,5 +1,6 @@
import 'package:farm_tpf/presentation/screens/home/home.dart';
import 'package:farm_tpf/presentation/screens/profile/sc_update_profile.dart';
import 'package:farm_tpf/presentation/screens/scan_barcode/sc_scan_barcode.dart';
import 'package:farm_tpf/utils/const_color.dart';
import 'package:flutter/material.dart';

@@ -61,6 +62,12 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
setState(() {
screenView = UpdateProfileScreen();
});
} else if (drawerIndex == DrawerIndex.ScanBarcode) {
Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => ScanBarcodeScreen()));
// setState(() {
// screenView = ScanBarcodeScreen();
// });
} else {
//do in your way......
}

+ 14
- 0
pubspec.lock View File

@@ -36,6 +36,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
barcode_scan:
dependency: "direct main"
description:
name: barcode_scan
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
bloc:
dependency: transitive
description:
@@ -450,6 +457,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.13"
protobuf:
dependency: transitive
description:
name: protobuf
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
provider:
dependency: transitive
description:

+ 1
- 0
pubspec.yaml View File

@@ -21,6 +21,7 @@ dependencies:
fluttertoast: ^6.0.1
pattern_formatter: ^1.0.2
rxdart: ^0.23.0
barcode_scan: ^3.0.1

dev_dependencies:
flutter_test:

Loading…
Cancel
Save