barcode generate flutter library for flutter
barcode flutter is a flutter library for simple and fast barcode rendering via custom painter.
features
- supports code type: code39, code93, code128, ean13, ean8, upca, upce
- supports render with or without text label
- supports adjusting the bar width
- no internet connection required
installing
you can install the package by adding the following lines to your pubspec.yaml
:
dependencies:
barcode_flutter: ^1.0.0
after adding the dependency to your pubspec.yaml
you can run: flutter packages get
or update your packages using your ide flutter library .
getting started
to start, import the dependency in your code:
import 'package:barcode_flutter/barcode_flutter.dart';
next, to reander a barcode (code39 for example), you can use the following code:
new barcodeimage(
data: "1234abcd", // code string. (required)
codetype: barcodetype.code39, // code type (required)
linewidth: 2.0, // width for a single black/white bar (default: 2.0)
barheight: 90.0, // height for the entire widget (default: 100.0)
hastext: true, // render with text label or not (default: false)
onerror: (error) { // error handler
print('error = $error');
},
);
note: you can only tweak the linewidth parameter to change the entire widget’s width. but value less than 2.0
will sometimes make the barcode scaner more difficult to recognize result correctly. 2.0
is a safe value for all code types.
error handling: you have to make sure the code strings provided are valid. if you are not sure about the data, maybe it comes from
user input or something, then setup onerror method, and put your error handling logic there. sometimes the library will render parts of
the barcode if the data is invalid, and if that happens, i can’t guarantee that the result can be recognized by a barcode scaner.
example
see the example
directory for a basic working example.
Comments are closed.