Skip to content

Commit ed81ffc

Browse files
committed
feat: Add hide gallery button option to barcode scanner
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.
1 parent f07bef0 commit ed81ffc

File tree

8 files changed

+85
-38
lines changed

8 files changed

+85
-38
lines changed

.flutter-plugins

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
file_selector_linux=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/file_selector_linux-0.9.2+1/
33
file_selector_macos=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/file_selector_macos-0.9.4/
44
file_selector_windows=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/file_selector_windows-0.9.3+1/
5-
flutter_plugin_android_lifecycle=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.19/
6-
image_picker=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker-1.1.1/
7-
image_picker_android=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_android-0.8.12+1/
5+
flutter_plugin_android_lifecycle=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.20/
6+
image_picker=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker-1.1.2/
7+
image_picker_android=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_android-0.8.12+3/
88
image_picker_for_web=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_for_web-3.0.4/
9-
image_picker_ios=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_ios-0.8.11+2/
9+
image_picker_ios=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_ios-0.8.12/
1010
image_picker_linux=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_linux-0.2.1+1/
1111
image_picker_macos=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_macos-0.2.1+1/
1212
image_picker_windows=/Users/arvindsangwan/.pub-cache/hosted/pub.dev/image_picker_windows-0.2.1+1/

.flutter-plugins-dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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"}
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"}

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,4 @@ migrate_working_dir/
2929
.packages
3030
build/
3131
.vscode
32-
.vsCode
33-
34-
.flutter-plugins
35-
.flutter-plugins-dependencies
32+
.vsCode

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 5.1.1+1
2+
3+
- Readme updated
4+
- gallery button hide option added
5+
16
## 5.1.1
27

38
**BREAKING CHANGES:**

README.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ import 'package:ai_barcode_scanner/ai_barcode_scanner.dart';
107107
108108
/// Simple example of using the barcode scanner.
109109
AiBarcodeScanner(
110-
onScan: (String value) {
111-
debugPrint(value);
112-
},
113110
onDetect: (BarcodeCapture barcodeCapture) {
114111
debugPrint(barcodeCapture);
115112
},
@@ -120,9 +117,6 @@ AiBarcodeScanner(
120117
controller: MobileScannerController(
121118
detectionSpeed: DetectionSpeed.noDuplicates,
122119
),
123-
onScan: (String value) {
124-
debugPrint(value);
125-
},
126120
onDetect: (BarcodeCapture barcodeCapture) {
127121
debugPrint(barcodeCapture);
128122
},
@@ -132,16 +126,40 @@ AiBarcodeScanner(
132126
/// Validator works on the raw string, not the decoded value.
133127
/// If you want to validate the scanner, use the [validate] parameter.
134128
AiBarcodeScanner(
135-
validate: (String value) {
136-
if(value.startsWith('http')) {
137-
return true;
138-
}
139-
return false;
140-
},
141-
onScan: (String value) {
142-
debugPrint(value);
143-
},
144-
),
129+
onDispose: () {
130+
/// This is called when the barcode scanner is disposed.
131+
/// You can write your own logic here.
132+
debugPrint("Barcode scanner disposed!");
133+
},
134+
controller: MobileScannerController(
135+
detectionSpeed: DetectionSpeed.noDuplicates,
136+
),
137+
onDetect: (BarcodeCapture capture) {
138+
/// The row string scanned barcode value
139+
final String? scannedValue =
140+
capture.barcodes.first.rawValue;
141+
142+
/// The `Uint8List` image is only available if `returnImage` is set to `true`.
143+
final Uint8List? image = capture.image;
144+
145+
/// row data of the barcode
146+
final Object? raw = capture.raw;
147+
148+
/// List of scanned barcodes if any
149+
final List<Barcode> barcodes = capture.barcodes;
150+
},
151+
validator: (value) {
152+
if (value.barcodes.isEmpty) {
153+
return false;
154+
}
155+
if (!(value.barcodes.first.rawValue
156+
?.contains('flutter.dev') ??
157+
false)) {
158+
return false;
159+
}
160+
return true;
161+
},
162+
),
145163
```
146164

147165
## Usage ([mobile_scanner](https://pub.dev/packages/mobile_scanner))

example/lib/main.dart

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import 'dart:developer';
2-
31
import 'package:ai_barcode_scanner/ai_barcode_scanner.dart';
2+
import 'package:flutter/foundation.dart';
43
import 'package:flutter/material.dart';
54

65
void main() {
@@ -45,18 +44,42 @@ class _HomePageState extends State<HomePage> {
4544
MaterialPageRoute(
4645
builder: (context) => AiBarcodeScanner(
4746
onDispose: () {
47+
/// This is called when the barcode scanner is disposed.
48+
/// You can write your own logic here.
4849
debugPrint("Barcode scanner disposed!");
4950
},
5051
controller: MobileScannerController(
5152
detectionSpeed: DetectionSpeed.noDuplicates,
5253
),
53-
onDetect: (p0) => setState(() {
54-
barcode = p0.barcodes.first.rawValue.toString();
55-
log(barcode, name: 'Barcode');
56-
}),
57-
validator: (p0) =>
58-
p0.barcodes.first.rawValue?.startsWith('https://') ??
59-
false,
54+
onDetect: (BarcodeCapture capture) {
55+
/// The row string scanned barcode value
56+
final String? scannedValue =
57+
capture.barcodes.first.rawValue;
58+
debugPrint("Barcode scanned: $scannedValue");
59+
60+
/// The `Uint8List` image is only available if `returnImage` is set to `true`.
61+
final Uint8List? image = capture.image;
62+
debugPrint("Barcode image: $image");
63+
64+
/// row data of the barcode
65+
final Object? raw = capture.raw;
66+
debugPrint("Barcode raw: $raw");
67+
68+
/// List of scanned barcodes if any
69+
final List<Barcode> barcodes = capture.barcodes;
70+
debugPrint("Barcode list: $barcodes");
71+
},
72+
validator: (value) {
73+
if (value.barcodes.isEmpty) {
74+
return false;
75+
}
76+
if (!(value.barcodes.first.rawValue
77+
?.contains('flutter.dev') ??
78+
false)) {
79+
return false;
80+
}
81+
return true;
82+
},
6083
),
6184
),
6285
);

lib/src/ai_barcode_scanner.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ class AiBarcodeScanner extends StatefulWidget {
169169
/// Hide title of the draggable sheet (default: false)
170170
final bool hideTitle;
171171

172+
/// Hide gallery button (default: false)
173+
final bool hideGalleryButton;
174+
172175
/// Upload from gallery button alignment
173176
/// default: bottom center, center, 0.75
174177
final AlignmentGeometry? buttonAlignment;
@@ -216,6 +219,7 @@ class AiBarcodeScanner extends StatefulWidget {
216219
this.buttonAlignment,
217220
this.actions,
218221
this.onPop,
222+
this.hideGalleryButton = false,
219223
});
220224

221225
@override
@@ -279,7 +283,7 @@ class _AiBarcodeScannerState extends State<AiBarcodeScanner> {
279283
: const Icon(Icons.flashlight_on_rounded),
280284
onPressed: () => controller.toggleTorch(),
281285
),
282-
if (isLandscape)
286+
if (isLandscape || !widget.hideGalleryButton)
283287
GalleryButton.icon(
284288
onImagePick: widget.onImagePick,
285289
onDetect: widget.onDetect,

pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: ai_barcode_scanner
22
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.
3-
version: 5.1.1
3+
version: 5.1.1+1
44
homepage: https://mohesu.com
55
repository: https://github.com/mohesu/barcode_scanner.git
66
issue_tracker: https://github.com/mohesu/barcode_scanner/issues
@@ -17,14 +17,14 @@ topics:
1717

1818
environment:
1919
sdk: ">=2.17.0 <4.0.0"
20-
flutter: ">=3.10.0 <4.0.0"
20+
flutter: ">=3.10.0"
2121

2222
dependencies:
2323
flutter:
2424
sdk: flutter
2525

2626
mobile_scanner: ^5.1.1
27-
image_picker: ^1.1.1
27+
image_picker: ^1.1.2
2828

2929
dev_dependencies:
3030
flutter_test:

0 commit comments

Comments
 (0)