barcode_flutter 1.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 94

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.

1.0.0 #

  • Initial release

1.0.1 #

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

1.0.2 #

  • Fix EAN8 code invalid checksum bug

1.1.0 #

  • Add BarCodeParams which allow custom params for each barcode type
  • Add ITF support
  • Fix issue #1, #9, #13 (See github page for details)

1.1.2 #

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

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:barcode_flutter/barcode_flutter.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Barcode Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(
        barcodes: [
          BarCodeItem(
            description: "Code39 with text",
            image: BarCodeImage(
              params: Code39BarCodeParams(
                "CODE39", 
                withText: true,
              ),
            ),
          ),
          BarCodeItem(
            description: "Code39",
            image: BarCodeImage(
              params: Code39BarCodeParams(
                "CODE39",
              ),
            ),
          ),
          BarCodeItem(
            description: "Code39 with text",
            image: BarCodeImage(
              params: Code93BarCodeParams(
                "CODE93",
                withText: true,
              ),
            ),
          ),
          BarCodeItem(
            description: "Code93",
            image: BarCodeImage(
              params: Code93BarCodeParams(
                "CODE93",
              ),
            ),
          ),
          BarCodeItem(
            description: "Code128 with text",
            image: BarCodeImage(
              params: Code128BarCodeParams(
                "CODE128",
                withText: true,
              ),
            ),
          ),
          BarCodeItem(
            description: "Code128",
            image: BarCodeImage(
              params: Code128BarCodeParams(
                "CODE128",
              ),
            ),
          ),
          BarCodeItem(
            description: "EAN8 with text",
            image: BarCodeImage(
              params: EAN8BarCodeParams(
                "65833254",
                withText: true,
              ),
            ),
          ),
          BarCodeItem(
            description: "EAN8",
            image: BarCodeImage(
              params: EAN8BarCodeParams(
                "65833254",
              ),
            ),
          ),
          BarCodeItem(
            description: "EAN13 with text",
            image: BarCodeImage(
              params: EAN13BarCodeParams(
                "9501101530003",
                withText: true,
              ),
            ),
          ),
          BarCodeItem(
            description: "EAN13",
            image: BarCodeImage(
              params: EAN13BarCodeParams(
                "9501101530003",
              ),
            ),
          ),
          BarCodeItem(
            description: "UPCA with text",
            image: BarCodeImage(
              params: UPCABarCodeParams(
                "123456789012",
                withText: true,
              ),
            ),
          ),
          BarCodeItem(
            description: "UPCA",
            image: BarCodeImage(
              params: UPCABarCodeParams(
                "123456789012",
              ),
            ),
          ),
          BarCodeItem(
            description: "UPCE with text",
            image: BarCodeImage(
              params: UPCEBarCodeParams(
                "00123457",
                withText: true,
              ),
            ),
          ),
          BarCodeItem(
            description: "UPCE",
            image: BarCodeImage(
              params: UPCEBarCodeParams(
                "00123457",
              ),
            ),
          ),
          BarCodeItem(
            description: "ITF with text",
            image: BarCodeImage(
              params: ITFBarCodeParams(
                "133175398642265258",
                withText: true,
              ),
            ),
          ),
          BarCodeItem(
            description: "ITF",
            image: BarCodeImage(
              params: ITFBarCodeParams(
                "133175398642265258",
              ),
            ),
          ),
          BarCodeItem(
            description: "Codabar with text",
            image: BarCodeImage(
              params: CodabarBarCodeParams(
                "A123456789B",
                withText: true,
              ),
            )
          ),
          BarCodeItem(
            description: "Codabar",
            image: BarCodeImage(
              params: CodabarBarCodeParams(
                "A123456789B",
              ),
            )
          )
        ],
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({this.barcodes});
  final List<BarCodeItem> barcodes;
  final String title = "BarCode Flutter";

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: ListView(
        children: widget.barcodes.map((element) {
          return Padding(
            padding: const EdgeInsets.all(10.0),
            child: Card(
              child: Column(
                children: <Widget>[
                  Align(
                    alignment: Alignment.centerLeft,
                    child: Text(
                      element.description,
                      textAlign: TextAlign.left,
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 20.0,
                        color: Colors.black45,
                      ),
                    ),
                  ),
                  Center(
                    child: Container(
                      padding: const EdgeInsets.all(10.0),
                      child: element.image,
                    ),
                  )
                ],
              ),
            ),
          );
        }).toList(),
      ),
    );
  }
}

class BarCodeItem {
  String description;
  BarCodeImage image;
  BarCodeItem({
    this.image,
    this.description,
  });
}

Use this package as a library

1. Depend on it

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


dependencies:
  barcode_flutter: ^1.1.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:barcode_flutter/barcode_flutter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
92
Health:
Code health derived from static analysis. [more]
92
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

We analyzed this package on Jul 12, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • barcode_flutter that is a package requiring null.

Health suggestions

Fix lib/src/barcode_image.dart. (-7.71 points)

Analysis of lib/src/barcode_image.dart reported 16 hints, including:

line 38 col 22: 'data' is deprecated and shouldn't be used.

line 39 col 22: 'codeType' is deprecated and shouldn't be used.

line 40 col 22: 'lineWidth' is deprecated and shouldn't be used.

line 41 col 22: 'barHeight' is deprecated and shouldn't be used.

line 42 col 22: 'hasText' is deprecated and shouldn't be used.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.58.0 < 3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety