flutter_barcode_scanner
a plugin for flutter apps that adds barcode scanning support on both android and ios.
try example
just download or download the repository, open the project in android studio/ vs code
, open pubspec.yaml
and click on packages get
.
connect device and hit run
.
to run on iphone you need to run from xcode first time and just make pod install
in example/ios
then run from xcode.
getting started
follow the steps for android and ios
please follow ios steps carefully
android
:zap: don’t worry, you don’t need to do anything.
ios – requires swift support
deployment target : 11
1. fresh start:
- create a new flutter project. please check for include swift support for ios code.
- after creating new flutter project open
/ios
project in xcode and set minimum deployment target to 11
and set swift version to 5. - after setting up the deployment target and swift version, close the xcode then run pod install in
/ios
in flutter project.
you have done with basic configuration now proceed to section how to use.
2. adding to existing flutter app:
if your existing ios code is swift then you just need to do following.
- set minimum deployment target to 10 and set swift version to 5.
- close the xcode and run pod install in
/ios
in flutter project. - now proceed to section how to use.
if your existing ios code is objective-c then you need to do following.
- create a new flutter project with same name at different location (don’t forget to check include swift support for ios code while creating)
- just copy newly created
/ios
folder from project and replace with existing/ios
. - open ios project in xcode and set minimum deployment target to 11 and set swift version to 5.
- run pod install in
/ios
note: if you did any changes in ios part before, you might need to make these configuration again
how to use ?
to use on ios, you will need to add the camera usage description.
to do that open the xcode and add camera usage description in info.plist
.
<key>nscamerausagedescription</key>
<string>camera permission is required for barcode scanning.</string>
after making the changes in android ans ios add flutter_barcode_scanner to pubspec.yaml
dependencies:
...
flutter_barcode_scanner: ^1.0.1
one time scan
- you need to import the package first.
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
- then use the
scanbarcode
method to access barcode scanning.
string barcodescanres = await flutterbarcodescanner.scanbarcode(
color_code,
cancel_button_text,
isshowflashicon,
scanmode);
here in scanbarcode
,
color_code
is hex-color which is the color of line in barcode overlay you can pass color of your choice,
cancel_button_text
is a text of cancel button on screen you can pass text of your choice and language,
isshowflashicon
is bool value used to show or hide the flash icon,
scanmode
is a enum in which user can pass any of { qr, barcode, default }
, if nothing is passed it will consider a default value which will be qr
.
it shows the graphics overlay like for barcode and qr.
note: currently, scanmode
is just to show the graphics overlay for barcode and qr. any of this mode selected will scan both qr and barcode.
continuous scan
- if you need to scan barcodes continuously without closing camera use
flutterbarcodescanner.getbarcodestreamreceiver
params will be same likeflutterbarcodescanner.scanbarcode
e.g.
flutterbarcodescanner.getbarcodestreamreceiver("#ff6666", "cancel", false, scanmode.default)
.listen((barcode) {
/// barcode to be used
});
Comments are closed.