9.6 C
London
Saturday, April 20, 2024

Flutter mobile_scanner not detecting QR codes on iOS gadgets


that is my first Stack Overflow publish! I’m intermediate at constructing Flutter apps and now I’m making an attempt to make use of the mobile_scanner 4.0.1 bundle in Flutter because it presents a pleasant customizeable fullscreen scanwindow. Detecting barcodes works as supposed on Android gadgets nonetheless on iOS gadgets, the _mobileScannerController nonetheless works (i.e. I can flip the digital camera round, restart the controller, activate flashlight and so on.), nevertheless it by no means detects a barcode and calls onDetect. My iOS gadgets have all had their digital camera app QR choices turned on in settings and I get no error message what so ever. The examined gadgets has ranged in age from 1 yr previous to 7 years previous.

I’m 100% sure I’ve adopted the directions on the best way to set up mobile_scanner accurately, I´ve tried older variations, previous and new iOS gadgets, turning QR choice in digital camera on and off (iPhone settings -> common -> digital camera…) and am afraid the issue lies exterior my code and in my set up somwhere. I’ve requested for NSCameraUsageDescription within the information.plist file. That is my code:

import 'dart:developer';


import 'dart:io';

import 'bundle:flutter/basis.dart';
import 'bundle:flutter/materials.dart';
import 'bundle:mobile_scanner/mobile_scanner.dart';

import 'scanner_error_widget.dart';

class BarcodeScannerWithScanWindow extends StatefulWidget {

  late _BarcodeScannerWithScanWindowState barcodeScannerState;
  @override
  _BarcodeScannerWithScanWindowState createState() {
    barcodeScannerState = _BarcodeScannerWithScanWindowState();
    return barcodeScannerState;
  }


  getState() => barcodeScannerState;
}

class _BarcodeScannerWithScanWindowState
    extends State<BarcodeScannerWithScanWindow> {

  refresh() {
    log("qr_scanner: Refreshing _mobileScannerController");
    _mobileScannerController.cease();
    _mobileScannerController.begin();
  }

  remaining MobileScannerController _mobileScannerController = MobileScannerController(
    codecs: [BarcodeFormat.qrCode],
    going through: CameraFacing.again,
    detectionSpeed: DetectionSpeed.noDuplicates,
    detectionTimeoutMs: 60*1000
  );


  Barcode? barcode;
  BarcodeCapture? seize;

  @override
  void initState() {
    log("INIT");
    tremendous.initState();
    _mobileScannerController.begin();
  }

  @override
  dispose() {
    log("DISPOSE");
    _mobileScannerController.dispose();
    tremendous.dispose();
  }

  Future<void> onDetect(BarcodeCapture barcode) async {
    log("DETECTED!");
    seize = barcode;
    setState(() => this.barcode = barcode.barcodes.first);
  }

  MobileScannerArguments? arguments;

  @override
  Widget construct(BuildContext context) {
    remaining scanWindow = Rect.fromCenter(
      middle: MediaQuery.of(context).dimension.middle(const Offset(0, -100)),//.middle(Offset.zero),
      width: 200,
      peak: 200,
    );


    return Scaffold(

      appBar: AppBar(
        elevation: 8.0,
        backgroundColor: Colours.black,
        automaticallyImplyLeading: false,


        // filters
        actions: [
          IconButton(
            onPressed: () {
              _showInfoDialog(context);
            },
            icon: Icon(Icons.info_outlined, color: Colors.white),
          ),
          const SizedBox(width: 8.0),
        ],
      ),


      physique: Builder(
        builder: (context) {
          return Stack(
            match: StackFit.develop,
            kids: [
              MobileScanner(
                fit: BoxFit.cover,
                scanWindow: scanWindow,
                controller: _mobileScannerController,
                onScannerStarted: (arguments) {
                  print("SCANNER STARTED");
                  setState(() {
                    this.arguments = arguments;
                  });
                },
                errorBuilder: (context, error, child) {
                  return ScannerErrorWidget(error: error);
                },
                onDetect: onDetect,
              ),

              CustomPaint(
                painter: ScannerOverlay(scanWindow),
              ),
              

            ],
          );
        },
      ),
    );
  }
}

Thanks for taking your time!

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here