Unhandled Exception: MissingPluginException(No implementation found for method scanBarcode on channel flutter_barcode_scanner)
1,123
Modify all reference FlutterFragmentActivity
to FlutterActivity
Java:
public class MainActivity extends FlutterActivity
Or for Kotlin:
class MainActivity: FlutterActivity()
More info here: Plugin Api Migration
Comments
-
Navid Shokoufeh over 1 year
im trying to create an barcode scanner by: https://pub.dev/packages/flutter_barcode_scanner/install.
when i run my codes i get this error :
E/flutter ( 9248): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method scanBarcode on channel flutter_barcode_scanner) E/flutter ( 9248): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7) E/flutter ( 9248): <asynchronous suspension> E/flutter ( 9248): #1 FlutterBarcodeScanner.scanBarcode (package:flutter_barcode_scanner/flutter_barcode_scanner.dart:43:9) E/flutter ( 9248): <asynchronous suspension> E/flutter ( 9248): #2 _MyAppState.scanBarcodeNormal (package:styleupapp1/main.dart:46:24) E/flutter ( 9248): <asynchronous suspension> E/flutter ( 9248):
here's my codes:
import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart'; void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { String _scanBarcode = 'Unknown'; @override void initState() { super.initState(); } Future<void> startBarcodeScanStream() async { FlutterBarcodeScanner.getBarcodeStreamReceiver( '#ff6666', 'Cancel', true, ScanMode.BARCODE)! .listen((barcode) => print(barcode)); } Future<void> scanQR() async { String barcodeScanRes; try { barcodeScanRes = await FlutterBarcodeScanner.scanBarcode( '#ff6666', 'Cancel', true, ScanMode.QR); print(barcodeScanRes); } on PlatformException { barcodeScanRes = 'Failed to get platform version.'; } //barcode scanner flutter ant setState(() { _scanBarcode = barcodeScanRes; }); } Future<void> scanBarcodeNormal() async { String barcodeScanRes; try { barcodeScanRes = await FlutterBarcodeScanner.scanBarcode( '#ff6666', 'Cancel', true, ScanMode.BARCODE); print(barcodeScanRes); } on PlatformException { barcodeScanRes = 'Failed to get platform version.'; } if (!mounted) return; setState(() { _scanBarcode = barcodeScanRes; }); } //barcode scanner flutter ant @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( appBar: AppBar(title: const Text('Barcode Scanner')), body: Builder(builder: (BuildContext context) { return Container( alignment: Alignment.center, child: Flex( direction: Axis.vertical, mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ ElevatedButton( onPressed: () => scanBarcodeNormal(), child: const Text('Barcode scan')), ElevatedButton( onPressed: () => scanQR(), child: const Text('QR scan')), ElevatedButton( onPressed: () => startBarcodeScanStream(), child: const Text('Barcode scan stream')), Text('Scan result : $_scanBarcode\n', style: const TextStyle(fontSize: 20)) ])); }))); } }
has anyone experienced this error? i don't know what to do i tried different ways and packages but everyone gave me same error . it's so important to me thanks for ur answers.
i asked once but no one answered. i really need to fix it.
-
Abhijith over 2 yearsTry to uninstall the app and run flutter clean and flutter pub get and run again
-
mmcdon20 over 2 yearsSee github.com/AmolGangadhare/flutter_barcode_scanner/issues/249 it looks like other people had the same issue and were able to solve it.
-
-
Navid Shokoufeh over 2 yearsit is true but at first my project doesn't has MainActivity.java file. so i created that by run this command :
flutter create -a java .
and then the problem solved for me.