Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

how to solve No implementation found for method scanBarcode on channel flutter_barcode_scanner Exception in Flutter

I'm trying to open the camera to scan the QR code when I press the button that supposes to open the QR code camera

it returns the following Exception

E/flutter (15313): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: MissingPluginException(No implementation found for method scanBarcode on channel flutter_barcode_scanner)
E/flutter (15313): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:157:7)
E/flutter (15313): <asynchronous suspension>
E/flutter (15313): #1      FlutterBarcodeScanner.scanBarcode (package:flutter_barcode_scanner/flutter_barcode_scanner.dart:42:28)
E/flutter (15313): <asynchronous suspension>
E/flutter (15313): #2      _ScanQRState.scanbarcode (package:restorantapp/pages/ScanQR.dart:15:15)
E/flutter (15313): <asynchronous suspension>
E/flutter (15313): 

here is my code below

import 'package:flutter/material.dart';
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';

class ScanQR extends StatefulWidget {
  @override
  _ScanQRState createState() => _ScanQRState();
}

class _ScanQRState extends State<ScanQR> {
  String code = "";
  String getCode = "";

  Future scanbarcode() async {
    getCode = await FlutterBarcodeScanner.scanBarcode(
        "#009922", "CANCEL", true, ScanMode.DEFAULT);

    setState(() {
      code = getCode;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Scan QR Code'),
        centerTitle: true,
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          FlatButton(
            color: Colors.blue,
            padding: EdgeInsets.all(16.0),
            child: Text('Scan QR Code',),
            onPressed: () {
              print('FlatButton pressed');
              scanbarcode();
            },
          ),
          Text(code)
        ],
      ),
    );
  }
}

I'm following a youtube tutorial in the video the app supposed to ask the user for permission but my app didn't ask for any permission I also try to add this permission to my manifest

<uses-permission android:name="android.permission.CAMERA" />
       <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
       <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

but it didn't work

!!!

question from:https://stackoverflow.com/questions/65864869/how-to-solve-no-implementation-found-for-method-scanbarcode-on-channel-flutter-b

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Execute following commands

flutter clean
flutter pub get

Then run your app again


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...