A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

Overview

r_scan

pub package

A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

Getting Started

Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  r_scan: last version

Android Platform

require read storage permission and camera permission, use permission_handler plugin.

import 'package:permission_handler/permission_handler.dart';

Future<bool> canReadStorage() async {
    if(Platform.isIOS) return true;
    var status = await PermissionHandler()
        .checkPermissionStatus(PermissionGroup.storage);
    if (status != PermissionStatus.granted) {
      var future = await PermissionHandler()
          .requestPermissions([PermissionGroup.storage]);
      for (final item in future.entries) {
        if (item.value != PermissionStatus.granted) {
          return false;
        }
      }
    } else {
      return true;
    }
    return true;
  }

Future<bool> canOpenCamera() async {
    var status =
        await PermissionHandler().checkPermissionStatus(PermissionGroup.camera);
    if (status != PermissionStatus.granted) {
      var future = await PermissionHandler()
          .requestPermissions([PermissionGroup.camera]);
      for (final item in future.entries) {
        if (item.value != PermissionStatus.granted) {
          return false;
        }
      }
    } else {
      return true;
    }
    return true;
  }

IOS Platform

add the permissions in your Info.plist

    
   
    NSCameraUsageDescription
   
	
   
    扫描二维码时需要使用您的相机
   
	
   
    NSPhotoLibraryUsageDescription
   
	
   
    扫描二维码时需要访问您的相册
   
	
   
    io.flutter.embedded_views_preview
   
    
   

no another.

Usage

1.scan Image File

final result=await RScan.scanImagePath('your file path');

2.scan Image url

final result=await RScan.scanImagePath('your image url');

3.scan Image memory

 ByteData data=await rootBundle.load('images/qrCode.png');
 final result=await RScan.scanImageMemory(data.buffer.asUint8List());

4.scan camera(new! please upgrade this plugin to v0.1,4)

  • Step First: Get available cameras
List<RScanCameraDescription> rScanCameras = await availableRScanCameras();;

if you want to get it in main() method, you can use this code.

List<RScanCameraDescription> rScanCameras;

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  rScanCameras = await availableRScanCameras();
  runApp(...);
}
  • Step Second:Use it.
class RScanCameraDialog extends StatefulWidget {
  @override
  _RScanCameraDialogState createState() => _RScanCameraDialogState();
}

class _RScanCameraDialogState extends State<RScanCameraDialog> {
  RScanCameraController _controller;
  bool isFirst = true;

  @override
  void initState() {
    super.initState();
    if (rScanCameras != null && rScanCameras.length > 0) {
      _controller = RScanCameraController(
          rScanCameras[1], RScanCameraResolutionPreset.max)
        ..addListener(() {
          final result = _controller.result;
          if (result != null) {
            if (isFirst) {
              Navigator.of(context).pop(result);
              isFirst = false;
            }
          }
        })
        ..initialize().then((_) {
          if (!mounted) {
            return;
          }
          setState(() {});
        });
    }
  }

  @override
  void dispose() {
    _controller?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    if (rScanCameras == null || rScanCameras.length == 0) {
      return Scaffold(
        body: Container(
          alignment: Alignment.center,
          child: Text('not have available camera'),
        ),
      );
    }
    if (!_controller.value.isInitialized) {
      return Container();
    }
    return Scaffold(
      backgroundColor: Colors.black,
      body: Stack(
        children: <Widget>[
          ScanImageView(
            child: AspectRatio(
              aspectRatio: _controller.value.aspectRatio,
              child: RScanCamera(_controller),
            ),
          ),
          Align(
              alignment: Alignment.bottomCenter,
              child: FutureBuilder(
                future: getFlashMode(),
                builder: _buildFlashBtn,
              ))
        ],
      ),
    );
  }
  Future<bool> getFlashMode() async {
    bool isOpen = false;
    try {
      isOpen = await _controller.getFlashMode();
    } catch (_) {}
    return isOpen;
  }

  Widget _buildFlashBtn(BuildContext context, AsyncSnapshot<bool> snapshot) {
    return snapshot.hasData
        ? Padding(
      padding:  EdgeInsets.only(bottom:24+MediaQuery.of(context).padding.bottom),
      child: IconButton(
          icon: Icon(snapshot.data ? Icons.flash_on : Icons.flash_off),
          color: Colors.white,
          iconSize: 46,
          onPressed: () {
            if (snapshot.data) {
              _controller.setFlashMode(false);
            } else {
              _controller.setFlashMode(true);
            }
            setState(() {});
          }),
    )
        : Container();
  }
}

5.scan view(Deprecated)

import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:r_scan/r_scan.dart';

class RScanDialog extends StatefulWidget {
  @override
  _RScanDialogState createState() => _RScanDialogState();
}

class _RScanDialogState extends State<RScanDialog> {
  RScanController _controller;

  @override
  void initState() {
    super.initState();
    initController();
  }
  bool isFirst=true;


  Future<void> initController() async {
    _controller = RScanController();
    _controller.addListener(() {

      final result = _controller.result;
      if (result != null) {
        if(isFirst){
          Navigator.of(context).pop(result);
          isFirst=false;
        }
      }
    });
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.black,
        body: FutureBuilder<bool>(
          future: canOpenCameraView(),
          builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
            if (snapshot.hasData && snapshot.data == true) {
              return ScanImageView(
                child: RScanView(
                  controller: _controller,
                ),
              );
            } else {
              return Container();
            }
          },
        ),
      ),
    );
  }

  Future<bool> canOpenCameraView() async {
    var status =
        await PermissionHandler().checkPermissionStatus(PermissionGroup.camera);
    if (status != PermissionStatus.granted) {
      var future = await PermissionHandler()
          .requestPermissions([PermissionGroup.camera]);
      for (final item in future.entries) {
        if (item.value != PermissionStatus.granted) {
          return false;
        }
      }
    } else {
      return true;
    }
    return true;
  }
}

6. open flash lamp / get flash lamp status.

You can use RScanController class.

//turn off the flash lamp.
await _controller.setFlashMode(false);

//turn on the flash lamp.
await _controller.setFlashMode(true);

// get the flash lamp status.

bool isOpen = await _controller.getFlashMode();

7. RScanResult

when you scan finish,will return the RScanResult...

class RScanResult {
  /// barcode type
  final RScanBarType type;

  ///barcode message
  final String message;

  ///barcode points include [x , y]
  final List<RScanPoint> points;
}
Comments
  • Unhandled Exception: type 'Future<List<Map<dynamic, dynamic>>?>' is not a subtype of type 'Future<List<Map<dynamic, dynamic>>>' in type cast

    Unhandled Exception: type 'Future>?>' is not a subtype of type 'Future>>' in type cast

    调用availableRScanCameras()时报错

    E/flutter (23097): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type 'Future<List<Map<dynamic, dynamic>>?>' is not a subtype of type 'Future<List<Map<dynamic, dynamic>>>' in type cast
    E/flutter (23097): #0      availableRScanCameras (package:r_scan/src/r_scan_camera.dart:17:9)
    E/flutter (23097): #1      _MyAppState.initState (package:flutter_cloud/main.dart:137:5)
    E/flutter (23097): #2      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4805:57)
    E/flutter (23097): #3      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4638:5)
    E/flutter (23097): #4      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3673:14)
    E/flutter (23097): #5      Element.updateChild (package:flutter/src/widgets/framework.dart:3425:18)
    E/flutter (23097): #6      RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1198:16)
    E/flutter (23097): #7      RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1167:5)
    E/flutter (23097): #8      RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1112:18)
    E/flutter (23097): #9      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2573:19)
    E/flutter (23097): #10     RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1111:13)
    E/flutter (23097): #11     WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:944:7)
    E/flutter (23097): #12     WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:924:7)
    E/flutter (23097): #13     _rootRun (dart:async/zone.dart:1420:47)
    E/flutter (23097): #14     _CustomZone.run (dart:async/zone.dart:1328:19)
    E/flutter (23097): #15     _CustomZone.runGuarded (dart:async/zone.dart:1236:7)
    E/flutter (23097): #16     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1276:23)
    E/flutter (23097): #17     _rootRun (dart:async/zone.dart:1428:13)
    E/flutter (23097): #18     _CustomZone.run (dart:async/zone.dart:1328:19)
    E/flutter (23097): #19     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1260:23)
    E/flutter (23097): #20     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
    E/flutter (23097): #21     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:395:19)
    E/flutter (23097): #22     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:426:5)
    E/flutter (23097): #23     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
    E/flutter (23097): 
    
    opened by git-boya 6
  • [Suggestion] Support scanning png image files

    [Suggestion] Support scanning png image files

    Hello, I have been unable to scan any png image file using this plugin. I think being able to scan png files could be very useful as screenshots in phones are generally in png format. So, I wanted to know if you have any plans for supporting that in your plugin?

    Thank you

    opened by chaudharydeepanshu 0
  • [Bug] Getting libjpeg error when trying to scan images taken from camera

    [Bug] Getting libjpeg error when trying to scan images taken from camera

    Hello, thanks for working on this plugin. I have been using this plugin to scan images from path but I'm receiving this error when trying to scan images taken through the camera,

    D/skia ( 6159): libjpeg error 116 <Corrupt JPEG data: 18 extraneous bytes before marker 0xdb> from output_message W/System ( 6159): A resource failed to call close. I/flutter ( 6159): TypedDataView(cid: 142) E/flutter ( 6159): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Null check operator used on a null value E/flutter ( 6159): #0 _HomeBodyState.build.

    To recreate the issue you can download the original image file from here and try scanning using the scanImagePath method.

    I also noticed that image scanning works fine if I optimize the image using an online optimizing tool like jpeg-optimizer.

    Thank you.

    opened by chaudharydeepanshu 0
  • 安卓6.0出现扫码后崩溃

    安卓6.0出现扫码后崩溃

    你好,大佬,安卓6.0扫码后出现崩溃,请解决一下,感谢!以下是错误信息: FATAL EXCEPTION: pool-9-thread-1 Process: com.gh.ghs, PID: 5962 java.lang.NoSuchMethodError: No interface method sort(Ljava/util/Comparator;)V in class Ljava/util/List; or its super classes (declaration of 'java.util.List' appears in /system/framework/core-libart.jar) at com.google.zxing.qrcode.detector.FinderPatternFinder.selectBestPatterns(FinderPatternFinder.java:616) at com.google.zxing.qrcode.detector.FinderPatternFinder.find(FinderPatternFinder.java:164) at com.google.zxing.qrcode.detector.Detector.detect(Detector.java:81) at com.google.zxing.qrcode.QRCodeReader.decode(QRCodeReader.java:77) at com.google.zxing.MultiFormatReader.decodeInternal(MultiFormatReader.java:173) at com.google.zxing.MultiFormatReader.decode(MultiFormatReader.java:57) at com.rhyme.r_scan.RScanCamera.RScanCamera$3$1.run(RScanCamera.java:401) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818) SurfaceTexture-1-5962-1 queueBuffer: slot 2 is dropped, handle=0x7f605c3cc0 SurfaceTexture-1-5962-1 queueBuffer: slot 0 is dropped, handle=0x7f605c3ae0 SurfaceTexture-1-5962-1 queueBuffer: slot 3 is dropped, handle=0x7f605c3d60

    opened by twopai 1
  • iOS crash when close scanPage

    iOS crash when close scanPage

    • (FlutterError * _Nullable)onCancelWithArguments:(id _Nullable)arguments { _eventSink = nil; [_eventChannel setStreamHandler:nil]; return nil; }

    [_eventChannel setStreamHandler:nil]; Thread 1: EXC_BAD_ACCESS (code=2, address=0x51932b7b90)

    opened by butterflyXX 1
Owner
PengHui Li
print("Hello World");
PengHui Li
A full-fledged camera app built with Flutter using the camera package.

Flutter Camera Demo A full-fledged camera app built with Flutter using the camera package. You can even add custom features to this app and customize

NguyenHoangDuc 5 Aug 19, 2022
A flutter plugin for device vibration and haptic feedback.

Vibrate A Flutter plugin to vibrate the device. This uses all the current Haptic Feedback APIs from Apple and provides similar feedback on Android. Ge

Rody Davis 82 Sep 14, 2022
System info plus - A Flutter plugin to get device Random Access Memory (RAM) size

system_info_plus A Flutter plugin to get device Random Access Memory (RAM) size.

Sebghatullah Yusuf 2 Aug 21, 2022
Gaimon - A Flutter plugin to fully support Haptic feedback with custom pattern

Gaimon A Flutter plugin to fully support Haptic feedback with custom pattern. ??

Dimitri Dessus 6 Aug 15, 2022
its just take image from gallery or camera and save to file (in flutter)

flutter_img_pdf A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

vivek kumar 0 Dec 28, 2021
I created a welcome page, login page and signup page using Flutter

welcome_page UI design for welcome page, signUp page & Login page by Joy Obor Getting Started This project is a starting point for a Flutter applicati

spyder 0 Dec 29, 2021
HappyNewYearAnimation-using-Flutter - A very delightful Welcome to 2022 with Flutter 🎉🎊🎆

happynewyearapp A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

Pratik JH 0 Jan 1, 2022
A shopper Flutter app that use BloC pattern and CRUD operations with different ways(memory/sqlite/http)

The project is maintained by a non-profit organisation, along with an amazing collections of Flutter samples. We're trying to make continuous commits

Flutter Samples 79 Sep 23, 2022
A flutter library for loading images from network, resizing as per container size and caching while being memory sensitive.

Optimized Cached Image A flutter library for loading images from network, resizing and caching them for memory sensitivity. This resizes and stores th

Anvith Bhat 70 Jun 30, 2022
A Demo application📱 which stores User feedback from 💙Flutter application into Google Sheets🗎 using Google AppScript.

?? Flutter ?? to Google Sheets ?? A Demo application which stores User feedback from Flutter application into Google Sheets using Google AppScript. Yo

Shreyas Patil 287 Sep 11, 2022
A simple widget for getting better feedback.

?? Using this library in a commercial product? Consider becoming a sponsor. A Flutter package for obtaining better feedback. It allows the user to pro

Jonas Uekötter 218 Sep 29, 2022
Hassan uni links - A Flutter plugin project to help with App/Deep Links (Android) and Universal Links and Custom URL schemes

Uni Links A Flutter plugin project to help with App/Deep Links (Android) and Uni

Hassan Al-Sabti 0 Feb 12, 2022
Flutter file based routing - File based routing and nested layouts for Flutter

Flutter File Based Routing I was inspired by the routing in remix.run with neste

Rody Davis 10 Jul 8, 2022
A simple flutter app that downloads a file from the internet, shows a custom-made download progress dialog and saves the file to device's internal storage

http_downloader A simple flutter app that downloads a file from the internet using the http plugin. It has a custom-designed progress dialog which dis

Akora Ing. Debrah Kwesi Buabeng 4 Apr 6, 2021
Flutterbodydetection - A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmentation APIs for both static images and live camera stream.

body_detection A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmen

null 14 Sep 15, 2022
Flutter plugin for selecting images from the Android and iOS image library, taking new pictures with the camera, and edit them before using such as rotation, cropping, adding sticker/text/filters.

advance_image_picker Flutter plugin for selecting multiple images from the Android and iOS image library, taking new pictures with the camera, and edi

Weta Vietnam 89 Sep 22, 2022
Real-time object detection in Flutter using camera and tflite plugin

For details: https://medium.com/@shaqian629/real-time-object-detection-in-flutter-b31c7ff9ef96 flutter_realtime_detection Real-time object detection i

Post_Swift 5 Jul 21, 2022
This is a flutter plugin to detect edges in a live camera, take the picture of detected edges object, crop it, and save.

edge_detection A flutter plugin to detect edges of objects, scan paper, detect corners, detect rectangles. It allows cropping of the detected object i

Sawan Kumar Bundelkhandi 170 Sep 18, 2022