Giter Site home page Giter Site logo

bigship / barcode.flutter Goto Github PK

View Code? Open in Web Editor NEW
59.0 9.0 27.0 169 KB

barcode generate library for Flutter

License: BSD 2-Clause "Simplified" License

Java 0.49% Objective-C 1.02% Dart 97.47% Ruby 1.02%
dart dart-library flutter flutter-package flutter-plugin flutter-widget flutter-examples barcode-generator barcode-images barcode

barcode.flutter's Introduction

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.

barcode.flutter's People

Contributors

bigship avatar henjiganai avatar kponda avatar v0l avatar yfer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

barcode.flutter's Issues

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 #1 (comment)

Barcode text paints outside the canvas

If the barcode height is set to 50, the text section is partially painted outside the canvas.
The image below shows Code39 but it happens for all formats.

text outside canvas

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)
════════════════════════════════════════════════════════════════════════════════

Null safety support

Hi, flutter 2.0 was landed and null safety is stable. Do you have any plan to migrate barcode_flutter to null safety?

get the result image

I want to a function to enlarge the two-dimensional code picture, so i need to get the two-dimensional code picture object. How can I get it

Add Image

I need to add to an image ('package: image / image.dart') how can I do it?

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.

Code93 barcode has extra bars on the end

Compare the following two barcode images.

The first is identical to that produced by several on-line barcode generators and matches the specification for code93 in wikipedia,
barcode
The second is from this package.
code93 demo

The package generated barcode has two extra solid bars and three extra spaces.
In all other respects, they are identical and both versions scan successfully.

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~

Can't correctly display Code128

There are two issues.

  1. According to your codes, this plugin only display code128B.
    Code128C is compression format if there are only digits
  2. I am trying to take byte array as input instead of string.
    Since code128 can be mixed with code128a/code128B/code128C.
    For example,
    1645907 is code128c with last digit is code128a
    The real raw bytes are 105, 16, 45, 90, 101, 23, 73,106
    101 indicate code128a is used and therefore, 23 represents '7' (not '07' in code128c)

Just Scan Barcode

Hello, How can I define the library to just scan barcode, I don't need scan QR in my project.

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, ),

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.