mohesu / barcode_scanner

A universal barcode and QR code scanner for Flutter based on MLKit. Uses CameraX on Android, AVFoundation on iOS and Apple Vision & AVFoundation on macOS.
Apache License 2.0
41 stars 31 forks source link

Scanner Crash while Opening #84

Open ravi-uleeco opened 10 months ago

ravi-uleeco commented 10 months ago

Screenshot_20240112_120649

Sometimes, the app scanner crashes. Can you guide me if anything I'm doing wrong?

This is my code: `import 'package:ai_barcode_scanner/ai_barcode_scanner.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart';

class ScanBarcodePage extends GetView { const ScanBarcodePage({super.key});

@override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.transparent, body: _buildBody(context), ); }

Widget _buildBody(BuildContext context) { return Stack( children: [ _scanView(context), SizedBox( width: MediaQuery.of(context).size.width, child: SafeArea( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox( height: MediaQuery.of(context).size.height * 0.45, ), const Text( "Align barcode in frame to scan", style: CTAppTextStyles.pageSmallTextStyle, ), ], ), ), ), SafeArea( child: Align( alignment: Alignment.topCenter, child: SizedBox( height: 50, child: Stack( children: [ const Center( child: Text( "Scan Barcode", style: TextStyle(color: CTColor.white), ), ), IconButton( onPressed: () { Get.back(); }, icon: const Icon( Icons.arrow_back_ios_new, ), iconSize: 15, ), ], ), ), ), ) ], ); }

Widget _scanView(BuildContext context) { return AiBarcodeScanner( onScan: (value) { debugPrint("value: $value"); }, onDetect: (capture) { final List barcodes = capture.barcodes; for (final barcode in barcodes) { debugPrint('Barcode found! ${barcode.rawValue}'); } }, controller: MobileScannerController( detectionSpeed: DetectionSpeed.noDuplicates, ), bottomBar: Container( height: 0, width: Size.infinite.width, color: Colors.transparent, ), ); } } `

rvndsngwn commented 10 months ago

Hi @ravi-uleeco Thanks for creating an issue.

can you share your code with 3 back ticks for easy to read you code.

it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting

It would also be helpful if you shared console logs.

Device android version no: package version:

ravi-uleeco commented 10 months ago

Can you please run the above code in Flutter you will get the idea bro. Don't have time to do this "share your code with 3 back ticks for easy to read you code".

Device Name: Samsung M-315F Device Version: Android 12 Package Details:- Flutter 3.13.4 • channel stable • https://github.com/flutter/flutter.git Framework • revision 367f9ea16b (4 months ago) • 2023-09-12 23:27:53 -0500 Engine • revision 9064459a8b Tools • Dart 3.1.2 • DevTools 2.25.0

rvndsngwn commented 10 months ago

Hi @ravi-uleeco, The latest version of this package has been released: ai_barcode_scanner: ^3.4.3. Let me know if you are still facing this issue.

JBtronic commented 7 months ago

Add controller.stop(); on onDetect: (capture) {} & also try using canPop: false or true. I don't know what is your use case. After detection, you are navigating push or pop, you know better!