barcode generate library for Flutter

Overview

Barcode Flutter is a Flutter library for simple and fast Barcode rendering via custom painter

screenshot


Update Notes

1.1.2

  • Add Codabar support
  • Fix wrong pattern for value 102 of Code128 (#20)

1.1.0

  • Add ITF support
  • Add BarCodeParams class for future expandability

1.0.2

  • Fix EAN8 code invalid checksum bug

1.0.1

  • Fix issue. Scanning problem when code128 contains character 'M'

1.0.0

  • Initial release

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.1.2

After adding the dependency to your pubspec.yaml you can run: flutter packages get or update your packages using your IDE.

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:

BarCodeImage(
  params: Code39BarCodeParams(
    "1234ABCD",
    lineWidth: 2.0,                // width for a single black/white bar (default: 2.0)
    barHeight: 90.0,               // height for the entire widget (default: 100.0)
    withText: 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.

FAQ

Has it been tested in production? Can I use it in production?

Yep! I've test it both on Android and iOS devices. Feel free to test it with any barcode scanner.

How about the other barcode types ?

I've only implemented some most commonly used barcode types. But feel free to send PR to include more barcode types.

License

Barcode flutter is released under BSD license. See LICENSE for details.

Comments
  • Barcode not centered

    Barcode not centered

    The barcode painter is not centered inside the barcode image as you can see on the image.

    screenshot_1543666980

    Steps to Reproduce:

    BarCodeImage( data: "1234243534557", codeType: BarCodeType.CodeEAN13, lineWidth: 3.0, backgroundColor: Colors.blue, ),

    opened by tobiasgubo 14
  • Add ITF Support

    Add ITF Support

    This also includes formatting and padding fixes.

    I've replaced the usage of BarCodeType with an abstract class BarCodeParams which will allow custom params for each barcode type, which i believe is a change worth implementing for future expand-ability.

    opened by v0l 4
  • some  barcode can not scan

    some barcode can not scan

    test to generate two barcode, the sencod can't not scan new BarCodeItem(type: BarCodeType.Code128, codeStr: "FS23030049234", description: "Code128", hasText: true), new BarCodeItem(type: BarCodeType.Code128, codeStr: "FS23030049MDUxMQ==", description: "Code128", hasText: true),

    barcode

    thanks~

    opened by yusonchang 4
  • Barcode is rendered outside the canvas

    Barcode is rendered outside the canvas

    @sooxiaotong FittedBox does not help with this. I've attached a screenshot to show that the barcode width is larger than the width computed by the package. And I am also generationg barcode for code128. I know the _calcCanvasWIdth() should be modified but I would have to invest some time to figure out how to do it.

    Anyway, I was hoping the author would provide some direct help. Thanks.

    screenshot

    Originally posted by @kaciula in https://github.com/bigship/barcode.flutter/issues/1#issuecomment-529095334

    opened by bruceanwyl 3
  • The pattern for value 102 of Code128 is wrong

    The pattern for value 102 of Code128 is wrong

    Code128 value 102 pattern is defined as 0x7a2, but it is actually 0x7ae. As a result, an incorrect barcode is output when FNC1 is output or when the check digit result is 102.

    opened by henjiganai 1
  • EAN8 with error

    EAN8 with error

    Hi! I try to display an EAN-8 barcode with value '90311130'. But I get an exception 'RangeError (index): Invalid value: Not in range 0..9, inclusive: 10'

    return Center( child: Container( child: BarCodeImage( data: '90311130', codeType: BarCodeType.CodeEAN8, barHeight: 100.0, hasText: true, onError: (error) { print("Generate barcode failed. error msg: $error"); }, ), ));

    Exception:

    ════════ Exception caught by rendering library ═════════════════════════════════ The following RangeError was thrown during paint(): RangeError (index): Invalid value: Not in range 0..9, inclusive: 10

    User-created ancestor of the error-causing widget was BarCodeImage lib/pages/mobil_cards.dart:392 When the exception was thrown, this was the stack #0 List.[] (dart:core-patch/growable_array.dart:147:60) #1 BarCodePainter._drawBarCodeEAN8 package:barcode_flutter/src/barcode_painter.dart:574 #2 BarCodePainter.paint package:barcode_flutter/src/barcode_painter.dart:30 #3 RenderCustomPaint._paintWithPainter package:flutter/…/rendering/custom_paint.dart:528 #4 RenderCustomPaint.paint package:flutter/…/rendering/custom_paint.dart:566 ... The following RenderObject was being processed when the exception was fired: RenderCustomPaint#74661 RenderObject: RenderCustomPaint#74661 parentData: offset=Offset(5.0, 5.0) (can use size) constraints: BoxConstraints(w=152.0, h=98.0) size: Size(152.0, 98.0) ════════════════════════════════════════════════════════════════════════════════

    opened by AndrewPiterov 1
  • Invalid ean8 checksum algorithm

    Invalid ean8 checksum algorithm

    In _drawBarCodeEAN8 checkCode is computed like

        checkCode = 10 - (sum2nd*3+sum3rd) % 10;
    

    If sum in bracets = 0, then checkCode will be 10, then it will throw.

    Algorithm should be like analogue to current EAN13 or UPC,

        if ((sum2nd + sum3rd * 3) % 10 == 0) {
          checkCode = 0;
        } else {
          checkCode = 10 - (sum2nd + sum3rd * 3) % 10;
        }
    

    I could not google standard for this. only resources like this

    opened by yfer 0
  • Add a simple golden test for BarCodeImage

    Add a simple golden test for BarCodeImage

    Hi, I want to migrate this package to null safety but realized that it doesn't have any tests. I'm not familiar with barcode spec so added a simple golden test for BarCodeImage. If this seems good, I'm willing to add more golden tests (and github action workflows).

    Thanks for the nice package 👍

    opened by shouichi 0
  • barcode 93 does not scan if data is longer than 15 characters

    barcode 93 does not scan if data is longer than 15 characters

    The checksum calculations do not roll the weighting values, they just get bigger. Weighting for "C" checksum should be 1..20 1..20 1..20 etc Weighting for "K" checksum should be 1..15 1..15 1..15 etc see http://www.barcodeisland.com/code93.phtml

    opened by bruceanwyl 0
  • Longer bar code renders outside canvas

    Longer bar code renders outside canvas

    This is not the same as #15. That was a miscalculation of the canvas size required to paint the barcode value with the specified line width.

    This issue occurs when the barcode widget is contained by a widget that is smaller than the calculated canvas size. In the example below, the barcode is in an Expanded widget between two SizedBox widgets. The code snippet below shows how the border around the canvas is applied.

        return Container(
          padding: EdgeInsets.all(8),
          decoration: BoxDecoration(
            color: Colors.red,
          ),
          child: BarCodeImage(
            data: "62733538535715976",
            codeType: BarCodeType.Code39,
            lineWidth: 2.5,
            barHeight: 150.0,
          ),
        );
    
    

    long barcode outside canvas

    So, rather than this, it would be better if the painter was aware of the actual width of canvas it has to work with and, if the canvas is too small, scale the barcode line width accordingly.

    opened by bruceanwyl 1
  • Color and layout

    Color and layout

    This branch contains fixes for the following issues... Barcode not centered #1 foregroundColor doesn't work #3 Barcode is rendered outside the canvas #13 Code93 barcode has extra bars on the end #14

    This is a breaking change, due to the backgroundColor and foregroundColor support added, so the version is updated to 2.0.0 in pubspec.yaml

    I also

    • Changed the demo layout a little to make it more obvious what is being displayed.
    • Removed "new" before all constructors as it is no longer required in Dart.
    • Apologise for changes that are only for layout caused by auto format in Visual Studio Code.
    • Renamed barcode_img.dart to barcode_image.dart to match your other conventions
    opened by bruceanwyl 1
Owner
Chenge
iOS/Python/C++
Chenge
Given a JSON string, this library will generate all the necessary Dart classes to parse and generate JSON.

JSON to Dart Given a JSON string, this library will generate all the necessary Dart classes to parse and generate JSON. This library is designed to ge

Javier Lecuona 1.2k Dec 25, 2022
A QR code/ barcode scanner made using Flutter.

QR Scanner A Flutter based QR/Bar code scanner app with dark mode and material design. Scan QR codes. Scan barcodes. Show result in a popup. Clicking

Hash Studios 10 Nov 15, 2022
Custom Camera, Barcode Scanner etc

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

Faizan Darwesh 0 Dec 30, 2021
QR Scanner and Barcode Scanner app

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

Muhammad Abair Mutarraf 18 Dec 8, 2022
bq Scanner : An QR Code and Barcode Scanner and Generator.

bq Scanner A Barcode Scanner. A QR Code Scanner. A Barcode Generator. A QR Code Generator. Visit bq Scanner at https://ritikpatle.github.io/bqscanner/

Ritik Patle 4 Jun 5, 2022
Spider - A small dart library to generate Assets dart code from assets folder.

Spider A small dart library to generate Assets dart code from assets folder. It generates dart class with static const variables in it which can be us

Birju Vachhani 159 Nov 8, 2022
DiceBear API wrapper. DiceBear is an avatar library for designers and developers. Generate random avatar profile pictures!

dice_bear Flutter Package DiceBear API wrapper. DiceBear is an avatar library for designers and developers. Generate random avatar profile pictures! C

Zaif Senpai 8 Oct 31, 2022
Generate responsive pages and apps on HTML, Tailwind, Flutter and SwiftUI.

Figma to Code Most design to code plugins are bad, some are even paid. This project aims to raise the bar by generating responsive layouts in Tailwind

Bernardo Ferrari 2.8k Jan 4, 2023
An extended version of Flutter Colors with more swatches and more flexibility to generate your own custom swatch.

Colours An extended version of Flutter Colors with more swatches and more flexibility to generate your own custom swatch. Getting Started In your flut

Salman S 4 Nov 23, 2021
Flutter video compress - Generate a new file by compressed video, and provide metadata. Get video thumbnail from a video path, supports JPEG/GIF. To reduce app size not using FFmpeg in IOS.

flutter_video_compress Generate a new path by compressed video, Choose to keep the source video or delete it by a parameter. Get video thumbnail from

天海るり 179 Dec 8, 2022
Home app - A dynamic flutter app which can be used to generate alerts, set alarms and send sms or call someone

first_app A dynamic flutter app which can be used to generate alerts, set alarms

null 0 Apr 9, 2022
Aditya 93 Dec 25, 2022
This is a command-line app written on dart language for flutter applications that will help you to generate some boilerplate code

dart-generator Manual installation: 1- generate a platform executable from code dart compile exe main.dart -o generator this will generate a new gene

One Studio 11 Oct 26, 2022
Custom style-dictionary transforms and formats to generate Flutter resources from a Figma Design Token plugin export..

style-dictionary-figma-flutter An extension to style-dictionary to support more custom types with Flutter as target platform. It supports the custom t

Aloïs Deniel 24 Dec 30, 2022
This is a mason brick you can use to generate code that get's you started right up with a flutter project

flutter_brick This is a mason brick you can use to generate code that gets you started right up with a flutter project A flutter brick created with th

Bruce Omukoko 3 Sep 16, 2022
A Flutter example about simple authentication with Auth0 and generate random QR code.

ryougoku This is Flutter example about simple authentication with Auth0 and generate random QR code. Environment setup Use need to create a .env.devel

null 4 Sep 24, 2022
A simple flutter application using #clean_architecture to generate random quotes using from #api

flutter_random_quotes_app_wth_clean_architecture A new Flutter project. Getting Started Project Structure ├── assets | ├── images | ├── 1x

Hossam Mohammad 2 Oct 4, 2022
Automatically generate profile picture with random first name and background color. But you can still provide pictures if you have them. As the default color, based on the name of the first letter. :fire: :fire: :fire:

FLUTTER PROFILE PICTURE Automatically generate profile picture with random first name and background color. But you can still provide pictures if you

Aditya Dharmawan Saputra 10 Dec 20, 2022
ThemeX is an easy theme manipulation. Only inform primary color and the ThemeX generate all color combination palette for you

ThemeX is an easy theme manipulation basied on Material Design. Only inform primary color and the ThemeX generate all color combination palette for yo

Michael S. Lopes 2 Jan 31, 2022