Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in Mobile Scanner Flutter library when reopening the QR Reader

I'm developing a Flutter project using the mobile_scanner library ^1.0.0 to read a QR code and I found an error when loading it the second time.

It happens me in the Android emulator, I tried it with different Android versions with the same result, you open the QR reader to read one, close it and try to read another one, then the reader just shows a black screen.

I tried to dispose the MobileScanner and some other things without success. I have found some other probably related issues in their Github but in the web and iOs side of Flutter.

The code I created just reproduces one example from its "official docs", a Widget with the Mobile Scanner object to read the QR and a callback to send the read text back.

class QrReadPage extends StatelessWidget {
  const QrReadPage({Key? key, required this.qrRead}) : super(key: key);
  final void Function(String) qrRead;

  @override
  Widget build(BuildContext context) {
    return MobileScanner(
        allowDuplicates: false,
        controller: MobileScannerController(),
        onDetect: (barcode, args) {
          String? code = barcode.rawValue;
          qrRead.call(code ?? 'Empty');
        });
  }
}

This Widget shows when you press a button in the main widget, you can see the full code of the example here.

I would like to know if somebody had to deal with this question before or I just need to create an issue in their Github.

like image 753
Alberto Méndez Avatar asked Nov 02 '25 06:11

Alberto Méndez


1 Answers

Even when you found a solution for this error I still wanted to share my experience with this library. I'm working since few days with this mentioned library and I have encountered many problems and bugs with this library. For example the GitHub repository examples are accessing to files which are not included in the library. e.g. import 'package:mobile_scanner_example/scanner_error_widget.dart';

The examples are not using only the library also it is using on the main repo some files which are completely missing in the library but which are necessary to get it work. I also get flutter warnings that wrong types are assigned to variables etc. especially in the barcode_scanner_controller.dart I have noticed that the library has missing files and that's the reason why it can't find some functions and classes. I have to add all the missing files by myself and this is actually something what the library should do because that's the reason why a library is made for.

Also the torch (flashlight) does not work properly and I get many other errors with this library. Even when the library is high rated I would recommend you and other users to use another library for scanning QR and bar codes. The documentation of this library is also very poor written. You see different codes in the GitHub repo and also in the documentation. There was also a bigger migration from an old version to a newer one. Don't waste your valuable time with a poor maintained library like this.

Using other libraries are probably more convenient and easier to use than this one. Don't be blinded by the good reviews on pub.dev for the library mobile_scanner

I hope I could help a bit

like image 123
esen Avatar answered Nov 03 '25 20:11

esen