Skip to content

Commit 22b31a1

Browse files
authored
Merge pull request #78 from amitjangra01/master
orientation issue fixed
2 parents 92634fb + 59490e9 commit 22b31a1

File tree

4 files changed

+191
-127
lines changed

4 files changed

+191
-127
lines changed

.flutter-plugins

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# This is a generated file; do not edit or check into version control.
2-
mobile_scanner=/Users/arvind/.pub-cache/hosted/pub.dev/mobile_scanner-3.4.1/
2+
mobile_scanner=C:\\Users\\amitj\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\mobile_scanner-3.5.5\\

.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":"mobile_scanner","path":"/Users/arvind/.pub-cache/hosted/pub.dev/mobile_scanner-3.4.1/","native_build":true,"dependencies":[]}],"android":[{"name":"mobile_scanner","path":"/Users/arvind/.pub-cache/hosted/pub.dev/mobile_scanner-3.4.1/","native_build":true,"dependencies":[]}],"macos":[{"name":"mobile_scanner","path":"/Users/arvind/.pub-cache/hosted/pub.dev/mobile_scanner-3.4.1/","native_build":true,"dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"mobile_scanner","path":"/Users/arvind/.pub-cache/hosted/pub.dev/mobile_scanner-3.4.1/","dependencies":[]}]},"dependencyGraph":[{"name":"mobile_scanner","dependencies":[]}],"date_created":"2023-10-02 23:08:02.151393","version":"3.13.6"}
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"mobile_scanner","path":"C:\\\\Users\\\\amitj\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\mobile_scanner-3.5.5\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"mobile_scanner","path":"C:\\\\Users\\\\amitj\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\mobile_scanner-3.5.5\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"mobile_scanner","path":"C:\\\\Users\\\\amitj\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\mobile_scanner-3.5.5\\\\","native_build":true,"dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"mobile_scanner","path":"C:\\\\Users\\\\amitj\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\mobile_scanner-3.5.5\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"mobile_scanner","dependencies":[]}],"date_created":"2023-12-14 11:07:19.823901","version":"3.16.0"}

example/pubspec.lock

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ packages:
5252
dependency: transitive
5353
description:
5454
name: collection
55-
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
55+
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
5656
url: "https://pub.dev"
5757
source: hosted
58-
version: "1.17.2"
58+
version: "1.18.0"
5959
cupertino_icons:
6060
dependency: "direct main"
6161
description:
@@ -187,10 +187,10 @@ packages:
187187
dependency: transitive
188188
description:
189189
name: meta
190-
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
190+
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
191191
url: "https://pub.dev"
192192
source: hosted
193-
version: "1.9.1"
193+
version: "1.10.0"
194194
mobile_scanner:
195195
dependency: transitive
196196
description:
@@ -232,18 +232,18 @@ packages:
232232
dependency: transitive
233233
description:
234234
name: stack_trace
235-
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
235+
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
236236
url: "https://pub.dev"
237237
source: hosted
238-
version: "1.11.0"
238+
version: "1.11.1"
239239
stream_channel:
240240
dependency: transitive
241241
description:
242242
name: stream_channel
243-
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
243+
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
244244
url: "https://pub.dev"
245245
source: hosted
246-
version: "2.1.1"
246+
version: "2.1.2"
247247
string_scanner:
248248
dependency: transitive
249249
description:
@@ -264,10 +264,10 @@ packages:
264264
dependency: transitive
265265
description:
266266
name: test_api
267-
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
267+
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
268268
url: "https://pub.dev"
269269
source: hosted
270-
version: "0.6.0"
270+
version: "0.6.1"
271271
typed_data:
272272
dependency: transitive
273273
description:
@@ -288,10 +288,10 @@ packages:
288288
dependency: transitive
289289
description:
290290
name: web
291-
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
291+
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
292292
url: "https://pub.dev"
293293
source: hosted
294-
version: "0.1.4-beta"
294+
version: "0.3.0"
295295
sdks:
296-
dart: ">=3.1.0 <4.0.0"
296+
dart: ">=3.2.0-194.0.dev <4.0.0"
297297
flutter: ">=3.10.0"

lib/src/ai_barcode_scanner.dart

Lines changed: 176 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -185,123 +185,187 @@ class _AiBarcodeScannerState extends State<AiBarcodeScanner> {
185185

186186
@override
187187
Widget build(BuildContext context) {
188-
/// keeps the app in portrait mode
189-
SystemChrome.setPreferredOrientations([
190-
DeviceOrientation.portraitUp,
191-
]);
192-
return Scaffold(
193-
bottomNavigationBar: widget.bottomBar ??
194-
ListTile(
195-
leading: IconButton(
196-
tooltip: "Switch Camera",
197-
onPressed: () => controller.switchCamera(),
198-
icon: ValueListenableBuilder<CameraFacing>(
199-
valueListenable: controller.cameraFacingState,
200-
builder: (context, state, child) {
201-
switch (state) {
202-
case CameraFacing.front:
203-
return const Icon(Icons.camera_front);
204-
case CameraFacing.back:
205-
return const Icon(Icons.camera_rear);
188+
// /// keeps the app in portrait mode
189+
// SystemChrome.setPreferredOrientations([
190+
// DeviceOrientation.portraitUp,
191+
// ]);
192+
return OrientationBuilder(
193+
builder: (context, orientation) {
194+
return Scaffold(
195+
bottomNavigationBar: orientation == Orientation.portrait
196+
? widget.bottomBar ??
197+
ListTile(
198+
leading: Builder(
199+
builder: (context) {
200+
return IconButton(
201+
tooltip: "Switch Camera",
202+
onPressed: () => controller.switchCamera(),
203+
icon: ValueListenableBuilder<CameraFacing>(
204+
valueListenable: controller.cameraFacingState,
205+
builder: (context, state, child) {
206+
switch (state) {
207+
case CameraFacing.front:
208+
return const Icon(
209+
Icons.camera_front);
210+
case CameraFacing.back:
211+
return const Icon(
212+
Icons.camera_rear);
213+
}
214+
},
215+
),
216+
);
217+
},
218+
),
219+
title: Text(
220+
widget.bottomBarText,
221+
textAlign: TextAlign.center,
222+
style: widget.bottomBarTextStyle,
223+
),
224+
trailing: Builder(
225+
builder: (context) {
226+
return IconButton(
227+
tooltip: "Torch",
228+
onPressed: () => controller.toggleTorch(),
229+
icon: ValueListenableBuilder<TorchState>(
230+
valueListenable: controller.torchState,
231+
builder: (context, state, child) {
232+
switch (state) {
233+
case TorchState.off:
234+
return const Icon(
235+
Icons.flash_off);
236+
case TorchState.on:
237+
return const Icon(
238+
Icons.flash_on);
239+
}
240+
},
241+
),
242+
);
243+
},
244+
),
245+
)
246+
: null,
247+
appBar: widget.appBar,
248+
body: Stack(
249+
250+
children: [
251+
MobileScanner(
252+
controller: controller,
253+
fit: widget.fit,
254+
errorBuilder: widget.errorBuilder,
255+
onScannerStarted: widget.onScannerStarted,
256+
placeholderBuilder: widget.placeholderBuilder,
257+
scanWindow: widget.scanWindow,
258+
startDelay: widget.startDelay ?? false,
259+
key: widget.key,
260+
onDetect: (BarcodeCapture barcode) async {
261+
widget.onDetect?.call(barcode);
262+
263+
if (barcode.barcodes.isEmpty) {
264+
log('Scanned Code is Empty');
265+
return;
206266
}
207-
},
208-
),
209-
),
210-
title: Text(
211-
widget.bottomBarText,
212-
textAlign: TextAlign.center,
213-
style: widget.bottomBarTextStyle,
214-
),
215-
trailing: IconButton(
216-
tooltip: "Torch",
217-
onPressed: () => controller.toggleTorch(),
218-
icon: ValueListenableBuilder<TorchState>(
219-
valueListenable: controller.torchState,
220-
builder: (context, state, child) {
221-
switch (state) {
222-
case TorchState.off:
223-
return const Icon(
224-
Icons.flash_off,
225-
color: Colors.grey,
226-
);
227-
case TorchState.on:
228-
return const Icon(
229-
Icons.flash_on,
230-
color: Colors.orange,
231-
);
267+
268+
final String code = barcode.barcodes.first.rawValue ?? "";
269+
270+
if ((widget.validator != null && !widget.validator!(code))) {
271+
setState(() {
272+
HapticFeedback.heavyImpact();
273+
log('Invalid Barcode => $code');
274+
_isSuccess = false;
275+
});
276+
return;
277+
}
278+
setState(() {
279+
_isSuccess = true;
280+
HapticFeedback.lightImpact();
281+
log('Barcode rawValue => $code');
282+
widget.onScan(code);
283+
});
284+
if (widget.canPop && mounted && Navigator.canPop(context)) {
285+
Navigator.pop(context);
286+
return;
232287
}
233288
},
234289
),
235-
),
236-
),
237-
appBar: widget.appBar,
238-
body: Stack(
239-
children: [
240-
MobileScanner(
241-
controller: controller,
242-
fit: widget.fit,
243-
errorBuilder: widget.errorBuilder,
244-
onScannerStarted: widget.onScannerStarted,
245-
placeholderBuilder: widget.placeholderBuilder,
246-
scanWindow: widget.scanWindow,
247-
startDelay: widget.startDelay ?? false,
248-
key: widget.key,
249-
onDetect: (BarcodeCapture barcode) async {
250-
widget.onDetect?.call(barcode);
251-
252-
if (barcode.barcodes.isEmpty) {
253-
log('Scanned Code is Empty');
254-
return;
255-
}
256-
257-
final String code = barcode.barcodes.first.rawValue ?? "";
258-
259-
if ((widget.validator != null && !widget.validator!(code))) {
260-
setState(() {
261-
HapticFeedback.heavyImpact();
262-
log('Invalid Barcode => $code');
263-
_isSuccess = false;
264-
});
265-
return;
266-
}
267-
setState(() {
268-
_isSuccess = true;
269-
HapticFeedback.lightImpact();
270-
log('Barcode rawValue => $code');
271-
widget.onScan(code);
272-
});
273-
if (widget.canPop && mounted && Navigator.canPop(context)) {
274-
Navigator.pop(context);
275-
return;
276-
}
277-
},
278-
),
279-
if (widget.showOverlay)
280-
Container(
281-
decoration: ShapeDecoration(
282-
shape: OverlayShape(
283-
borderRadius: widget.borderRadius,
284-
borderColor: ((_isSuccess ?? false) && widget.showSuccess)
285-
? widget.successColor
286-
: (!(_isSuccess ?? true) && widget.showError)
287-
? widget.errorColor
288-
: widget.borderColor,
289-
borderLength: widget.borderLength,
290-
borderWidth: widget.borderWidth,
291-
cutOutSize: widget.cutOutSize,
292-
cutOutBottomOffset: widget.cutOutBottomOffset,
293-
cutOutWidth: widget.cutOutWidth,
294-
cutOutHeight: widget.cutOutHeight,
295-
overlayColor: ((_isSuccess ?? false) && widget.showSuccess)
296-
? widget.successColor.withOpacity(0.4)
297-
: (!(_isSuccess ?? true) && widget.showError)
298-
? widget.errorColor.withOpacity(0.4)
299-
: widget.overlayColor,
290+
if (widget.showOverlay)
291+
Container(
292+
decoration: ShapeDecoration(
293+
shape: OverlayShape(
294+
borderRadius: widget.borderRadius,
295+
borderColor: ((_isSuccess ?? false) && widget.showSuccess)
296+
? widget.successColor
297+
: (!(_isSuccess ?? true) && widget.showError)
298+
? widget.errorColor
299+
: widget.borderColor,
300+
borderLength: widget.borderLength,
301+
borderWidth: widget.borderWidth,
302+
cutOutSize: widget.cutOutSize,
303+
cutOutBottomOffset: widget.cutOutBottomOffset,
304+
cutOutWidth: widget.cutOutWidth,
305+
cutOutHeight: widget.cutOutHeight,
306+
overlayColor:
307+
((_isSuccess ?? false) && widget.showSuccess)
308+
? widget.successColor.withOpacity(0.4)
309+
: (!(_isSuccess ?? true) && widget.showError)
310+
? widget.errorColor.withOpacity(0.4)
311+
: widget.overlayColor,
312+
),
313+
),
300314
),
301-
),
302-
),
303-
],
304-
),
315+
if(orientation == Orientation.landscape)
316+
Align(
317+
alignment: Alignment.centerRight,
318+
child: Container(
319+
padding: const EdgeInsets.all(12),
320+
decoration: const BoxDecoration(
321+
color: Colors.white,
322+
shape: BoxShape.rectangle,),
323+
324+
child: Column(
325+
mainAxisAlignment: MainAxisAlignment.spaceAround,
326+
children: [
327+
IconButton(
328+
tooltip: "Switch Camera",
329+
onPressed: () => controller.switchCamera(),
330+
icon: ValueListenableBuilder<CameraFacing>(
331+
valueListenable: controller.cameraFacingState,
332+
builder: (context, state, child) {
333+
switch (state) {
334+
case CameraFacing.front:
335+
return const Icon(
336+
Icons.camera_front);
337+
case CameraFacing.back:
338+
return const Icon(
339+
Icons.camera_rear);
340+
}
341+
},
342+
),
343+
),
344+
IconButton(
345+
tooltip: "Torch",
346+
onPressed: () => controller.toggleTorch(),
347+
icon: ValueListenableBuilder<TorchState>(
348+
valueListenable: controller.torchState,
349+
builder: (context, state, child) {
350+
switch (state) {
351+
case TorchState.off:
352+
return const Icon(
353+
Icons.flash_off);
354+
case TorchState.on:
355+
return const Icon(
356+
Icons.flash_on);
357+
}
358+
},
359+
),
360+
),
361+
],
362+
),
363+
),
364+
)
365+
],
366+
),
367+
);
368+
},
305369
);
306370
}
307371
}

0 commit comments

Comments
 (0)