Skip to content

Commit

Permalink
feat: Add hide gallery button option to barcode scanner
Browse files Browse the repository at this point in the history
This commit adds a new option to the barcode scanner that allows hiding the gallery button. The `hideGalleryButton` parameter has been added to the `AiBarcodeScanner` widget, and when set to `true`, the gallery button will not be displayed on the scanner screen. This provides more flexibility for customizing the scanner UI.
  • Loading branch information
rvndsngwn committed Jun 27, 2024
1 parent f07bef0 commit ed81ffc
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 38 deletions.
8 changes: 4 additions & 4 deletions .flutter-plugins
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
file_selector_linux=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/file_selector_linux-0.9.2+1/
file_selector_macos=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/file_selector_macos-0.9.4/
file_selector_windows=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/file_selector_windows-0.9.3+1/
flutter_plugin_android_lifecycle=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.19/
image_picker=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker-1.1.1/
image_picker_android=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_android-0.8.12+1/
flutter_plugin_android_lifecycle=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.20/
image_picker=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker-1.1.2/
image_picker_android=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_android-0.8.12+3/
image_picker_for_web=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_for_web-3.0.4/
image_picker_ios=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_ios-0.8.11+2/
image_picker_ios=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_ios-0.8.12/
image_picker_linux=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_linux-0.2.1+1/
image_picker_macos=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_macos-0.2.1+1/
image_picker_windows=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_windows-0.2.1+1/
Expand Down
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"image_picker_ios","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_ios-0.8.11+2/","native_build":true,"dependencies":[]},{"name":"mobile_scanner","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/mobile_scanner-5.1.1/","native_build":true,"dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.19/","native_build":true,"dependencies":[]},{"name":"image_picker_android","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_android-0.8.12+1/","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]},{"name":"mobile_scanner","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/mobile_scanner-5.1.1/","native_build":true,"dependencies":[]}],"macos":[{"name":"file_selector_macos","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/file_selector_macos-0.9.4/","native_build":true,"dependencies":[]},{"name":"image_picker_macos","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_macos-0.2.1+1/","native_build":false,"dependencies":["file_selector_macos"]},{"name":"mobile_scanner","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/mobile_scanner-5.1.1/","native_build":true,"dependencies":[]}],"linux":[{"name":"file_selector_linux","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/file_selector_linux-0.9.2+1/","native_build":true,"dependencies":[]},{"name":"image_picker_linux","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_linux-0.2.1+1/","native_build":false,"dependencies":["file_selector_linux"]}],"windows":[{"name":"file_selector_windows","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/file_selector_windows-0.9.3+1/","native_build":true,"dependencies":[]},{"name":"image_picker_windows","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_windows-0.2.1+1/","native_build":false,"dependencies":["file_selector_windows"]}],"web":[{"name":"image_picker_for_web","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_for_web-3.0.4/","dependencies":[]},{"name":"mobile_scanner","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/mobile_scanner-5.1.1/","dependencies":[]}]},"dependencyGraph":[{"name":"file_selector_linux","dependencies":[]},{"name":"file_selector_macos","dependencies":[]},{"name":"file_selector_windows","dependencies":[]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["image_picker_android","image_picker_for_web","image_picker_ios","image_picker_linux","image_picker_macos","image_picker_windows"]},{"name":"image_picker_android","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"image_picker_for_web","dependencies":[]},{"name":"image_picker_ios","dependencies":[]},{"name":"image_picker_linux","dependencies":["file_selector_linux"]},{"name":"image_picker_macos","dependencies":["file_selector_macos"]},{"name":"image_picker_windows","dependencies":["file_selector_windows"]},{"name":"mobile_scanner","dependencies":[]}],"date_created":"2024-05-25 23:09:40.081612","version":"3.22.1"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"image_picker_ios","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_ios-0.8.12/","native_build":true,"dependencies":[]},{"name":"mobile_scanner","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/mobile_scanner-5.1.1/","native_build":true,"dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.20/","native_build":true,"dependencies":[]},{"name":"image_picker_android","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_android-0.8.12+3/","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]},{"name":"mobile_scanner","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/mobile_scanner-5.1.1/","native_build":true,"dependencies":[]}],"macos":[{"name":"file_selector_macos","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/file_selector_macos-0.9.4/","native_build":true,"dependencies":[]},{"name":"image_picker_macos","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_macos-0.2.1+1/","native_build":false,"dependencies":["file_selector_macos"]},{"name":"mobile_scanner","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/mobile_scanner-5.1.1/","native_build":true,"dependencies":[]}],"linux":[{"name":"file_selector_linux","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/file_selector_linux-0.9.2+1/","native_build":true,"dependencies":[]},{"name":"image_picker_linux","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_linux-0.2.1+1/","native_build":false,"dependencies":["file_selector_linux"]}],"windows":[{"name":"file_selector_windows","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/file_selector_windows-0.9.3+1/","native_build":true,"dependencies":[]},{"name":"image_picker_windows","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_windows-0.2.1+1/","native_build":false,"dependencies":["file_selector_windows"]}],"web":[{"name":"image_picker_for_web","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_for_web-3.0.4/","dependencies":[]},{"name":"mobile_scanner","path":"/Users/arvindsangwan/.pub-cache/hosted/pub.dev/mobile_scanner-5.1.1/","dependencies":[]}]},"dependencyGraph":[{"name":"file_selector_linux","dependencies":[]},{"name":"file_selector_macos","dependencies":[]},{"name":"file_selector_windows","dependencies":[]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["image_picker_android","image_picker_for_web","image_picker_ios","image_picker_linux","image_picker_macos","image_picker_windows"]},{"name":"image_picker_android","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"image_picker_for_web","dependencies":[]},{"name":"image_picker_ios","dependencies":[]},{"name":"image_picker_linux","dependencies":["file_selector_linux"]},{"name":"image_picker_macos","dependencies":["file_selector_macos"]},{"name":"image_picker_windows","dependencies":["file_selector_windows"]},{"name":"mobile_scanner","dependencies":[]}],"date_created":"2024-06-27 12:00:39.264106","version":"3.22.2"}
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,4 @@ migrate_working_dir/
.packages
build/
.vscode
.vsCode

.flutter-plugins
.flutter-plugins-dependencies
.vsCode
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 5.1.1+1

- Readme updated
- gallery button hide option added

## 5.1.1

**BREAKING CHANGES:**
Expand Down
50 changes: 34 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ import 'package:ai_barcode_scanner/ai_barcode_scanner.dart';
/// Simple example of using the barcode scanner.
AiBarcodeScanner(
onScan: (String value) {
debugPrint(value);
},
onDetect: (BarcodeCapture barcodeCapture) {
debugPrint(barcodeCapture);
},
Expand All @@ -120,9 +117,6 @@ AiBarcodeScanner(
controller: MobileScannerController(
detectionSpeed: DetectionSpeed.noDuplicates,
),
onScan: (String value) {
debugPrint(value);
},
onDetect: (BarcodeCapture barcodeCapture) {
debugPrint(barcodeCapture);
},
Expand All @@ -132,16 +126,40 @@ AiBarcodeScanner(
/// Validator works on the raw string, not the decoded value.
/// If you want to validate the scanner, use the [validate] parameter.
AiBarcodeScanner(
validate: (String value) {
if(value.startsWith('http')) {
return true;
}
return false;
},
onScan: (String value) {
debugPrint(value);
},
),
onDispose: () {
/// This is called when the barcode scanner is disposed.
/// You can write your own logic here.
debugPrint("Barcode scanner disposed!");
},
controller: MobileScannerController(
detectionSpeed: DetectionSpeed.noDuplicates,
),
onDetect: (BarcodeCapture capture) {
/// The row string scanned barcode value
final String? scannedValue =
capture.barcodes.first.rawValue;
/// The `Uint8List` image is only available if `returnImage` is set to `true`.
final Uint8List? image = capture.image;
/// row data of the barcode
final Object? raw = capture.raw;
/// List of scanned barcodes if any
final List<Barcode> barcodes = capture.barcodes;
},
validator: (value) {
if (value.barcodes.isEmpty) {
return false;
}
if (!(value.barcodes.first.rawValue
?.contains('flutter.dev') ??
false)) {
return false;
}
return true;
},
),
```

## Usage ([mobile_scanner](https://pub.dev/packages/mobile_scanner))
Expand Down
41 changes: 32 additions & 9 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:developer';

import 'package:ai_barcode_scanner/ai_barcode_scanner.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void main() {
Expand Down Expand Up @@ -45,18 +44,42 @@ class _HomePageState extends State<HomePage> {
MaterialPageRoute(
builder: (context) => AiBarcodeScanner(
onDispose: () {
/// This is called when the barcode scanner is disposed.
/// You can write your own logic here.
debugPrint("Barcode scanner disposed!");
},
controller: MobileScannerController(
detectionSpeed: DetectionSpeed.noDuplicates,
),
onDetect: (p0) => setState(() {
barcode = p0.barcodes.first.rawValue.toString();
log(barcode, name: 'Barcode');
}),
validator: (p0) =>
p0.barcodes.first.rawValue?.startsWith('https://') ??
false,
onDetect: (BarcodeCapture capture) {
/// The row string scanned barcode value
final String? scannedValue =
capture.barcodes.first.rawValue;
debugPrint("Barcode scanned: $scannedValue");

/// The `Uint8List` image is only available if `returnImage` is set to `true`.
final Uint8List? image = capture.image;
debugPrint("Barcode image: $image");

/// row data of the barcode
final Object? raw = capture.raw;
debugPrint("Barcode raw: $raw");

/// List of scanned barcodes if any
final List<Barcode> barcodes = capture.barcodes;
debugPrint("Barcode list: $barcodes");
},
validator: (value) {
if (value.barcodes.isEmpty) {
return false;
}
if (!(value.barcodes.first.rawValue
?.contains('flutter.dev') ??
false)) {
return false;
}
return true;
},
),
),
);
Expand Down
6 changes: 5 additions & 1 deletion lib/src/ai_barcode_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ class AiBarcodeScanner extends StatefulWidget {
/// Hide title of the draggable sheet (default: false)
final bool hideTitle;

/// Hide gallery button (default: false)
final bool hideGalleryButton;

/// Upload from gallery button alignment
/// default: bottom center, center, 0.75
final AlignmentGeometry? buttonAlignment;
Expand Down Expand Up @@ -216,6 +219,7 @@ class AiBarcodeScanner extends StatefulWidget {
this.buttonAlignment,
this.actions,
this.onPop,
this.hideGalleryButton = false,
});

@override
Expand Down Expand Up @@ -279,7 +283,7 @@ class _AiBarcodeScannerState extends State<AiBarcodeScanner> {
: const Icon(Icons.flashlight_on_rounded),
onPressed: () => controller.toggleTorch(),
),
if (isLandscape)
if (isLandscape || !widget.hideGalleryButton)
GalleryButton.icon(
onImagePick: widget.onImagePick,
onDetect: widget.onDetect,
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ai_barcode_scanner
description: A universal AI barcode and QR code scanner for Flutter based on MLKit. Uses CameraX on Android, AVFoundation on iOS and Apple Vision & AVFoundation on macOS.
version: 5.1.1
version: 5.1.1+1
homepage: https://mohesu.com
repository: https://github.com/mohesu/barcode_scanner.git
issue_tracker: https://github.com/mohesu/barcode_scanner/issues
Expand All @@ -17,14 +17,14 @@ topics:

environment:
sdk: ">=2.17.0 <4.0.0"
flutter: ">=3.10.0 <4.0.0"
flutter: ">=3.10.0"

dependencies:
flutter:
sdk: flutter

mobile_scanner: ^5.1.1
image_picker: ^1.1.1
image_picker: ^1.1.2

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit ed81ffc

Please sign in to comment.