amal
amal

Reputation: 41

No implementation found for method scan on channel flutter com.apptresoftwore.barcode_scan

I tried to create a QRCode scanner in my mobile application using Flutter.I add the package barcode_scan in pubspec.yaml and the permission to the camera But everytime the same error was showed that no imlimentation found for method scan i can't found the solution.this is my code

import 'package:flutter/material.dart';
import 'package:barcode_scan/barcode_scan.dart';
import 'dart:async';
import 'package:flutter/services.dart';
class MyHomePage extends StatefulWidget{
@override
_MyHomePageState createState()=> new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String result = "Hey there !";

 Future _scanQR() async {
 try {
  String qrResult = await BarcodeScanner.scan();
  setState(() {
    result = qrResult;
   });
  } on PlatformException catch (ex) {
  if (ex.code == BarcodeScanner.CameraAccessDenied) {
    setState(() {
      result = "Camera permission was denied";
    });
  } else {
    setState(() {
      result = "Unknown Error $ex";
    });
  }
  } on FormatException {
  setState(() {
    result = "You pressed the back button before scanning anything";
  });
  } catch (ex) {
  setState(() {
    result = "Unknown Error $ex";
  });
  }
  }

  @override
  Widget build(BuildContext context) {
  return Scaffold(
   appBar: AppBar(
    title: Text("QR Scanner"),
    ),
   body: Center(
    child: Text(
      result,
      style: new TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),
    ),
    ),
    floatingActionButton: FloatingActionButton.extended(
    icon: Icon(Icons.camera_alt),
    label: Text("Scan"),
    onPressed: _scanQR,
    ),
    floatingActionButtonLocation: 
    FloatingActionButtonLocation.centerFloat,
    );
    }
    }

Upvotes: 2

Views: 9363

Answers (1)

Omatt
Omatt

Reputation: 10463

The error "No implementation found for method..." is usually caused when Flutter is unable to find the method called from the package due to the plugin not being properly added to the project. The same issue can also be encountered if the plugin used doesn't support the targeted platform. But since barcode_scan plugin seems to support both iOS and Android, this may have been caused by the former.

You can try running flutter pub get to verify that the plugins have been added to the project and run the app using full restart to ensure that all packages added are compiled.

I've also noticed that barcode_scan has been discontinued as of this writing. The plugin may still work as expected, but it won't be receiving further updates from its developers. You can also check other barcode scanner plugins from pub.dev that may fit your use case.

Upvotes: 1

Related Questions