QR.Flutter Is A Flutter Library for Simple and Fast QR Code

QR.Flutter is a Flutter library for simple and fast QR code rendering via a Widget or custom painter.

Need help?

Please do not submit an issue for a "How do i ..?" or "What is the deal with ..?" type question. They will pretty much be closed instantly. If you have questions, please ask them on the Discussions board or on Stack Overflow. They will get answered there.

Using issues creates a large amount of noise and results in real issues getting fixed slower.

Features

  • Null safety
  • Built on QR - Dart
  • Automatic QR code version/type detection or manual entry
  • Supports QR code versions 1 - 40
  • Error correction / redundancy
  • Configurable output size, padding, background and foreground colors
  • Supports image overlays
  • Export to image data to save to file or use in memory
  • No internet connection required

Installing

Version compatibility: 4.0.0+ supports null safety and requires a version of Flutter that is compatible. If you're using an incompatible version of flutter, please use a 3.x version of this library.

You should add the following to your pubspec.yaml file:

dependencies:
  qr_flutter: ^4.1.0

Note: If you're using the Flutter master channel, if you encounter build issues, or want to try the latest and greatest then you should use the master branch and not a specific release version. To do so, use the following configuration in your pubspec.yaml:

dependencies:
  qr_flutter:
    git:
      url: https://github.com/theyakka/qr.flutter.git

Keep in mind the master branch could be unstable.

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:qr_flutter/qr_flutter.dart';

Next, to render a basic QR code you can use the following code (or something like it):

QrImageView(
  data: '1234567890',
  version: QrVersions.auto,
  size: 200.0,
),

Depending on your data requirements you may want to tweak the QR code output. The following options are available:

PropertyTypeDescription
versionintQrVersions.auto or a value between 1 and 40. See http://www.qrcode.com/en/about/version.html for limitations and details.
errorCorrectionLevelintA value defined on QrErrorCorrectLevel. e.g.: QrErrorCorrectLevel.L.
sizedoubleThe (square) size of the image. If not given, will auto size using shortest size constraint.
paddingEdgeInsetsPadding surrounding the QR code data.
backgroundColorColorThe background color (default is none).
eyeStyleQrEyeStyleConfigures the QR code eyes' (corners') shape and color.
dataModuleStyleQrDataModuleStyleConfigures the shape and the color of the dots.
gaplessboolAdds an extra pixel in size to prevent gaps (default is true).
errorStateBuilderQrErrorBuilderAllows you to show an error state Widget in the event there is an error rendering the QR code (e.g.: version is too low, input is too long, etc).
constrainErrorBoundsboolIf true, the error Widget will be constrained to the square that the QR code was going to be drawn in. If false, the error state Widget will grow/shrink to whatever size it needs.
embeddedImageImageProviderAn ImageProvider that defines an image to be overlaid in the center of the QR code.
embeddedImageStyleQrEmbeddedImageStyleProperties to style the embedded image.
embeddedImageEmitsErrorboolIf true, any failure to load the embedded image will trigger the errorStateBuilder or render an empty Container. If false, the QR code will be rendered and the embedded image will be ignored.
semanticsLabelStringsemanticsLabel will be used by screen readers to describe the content of the QR code.

Examples

There is a simple, working, example Flutter app in the /example directory. You can use it to play with all the options.

Also, the following examples give you a quick overview on how to use the library.

A basic QR code will look something like:

QrImageView(
  data: 'This is a simple QR code',
  version: QrVersions.auto,
  size: 320,
  gapless: false,
)

A QR code with an image (from your application's assets) will look like:

QrImageView(
  data: 'This QR code has an embedded image as well',
  version: QrVersions.auto,
  size: 320,
  gapless: false,
  embeddedImage: AssetImage('assets/images/my_embedded_image.png'),
  embeddedImageStyle: QrEmbeddedImageStyle(
    size: Size(80, 80),
  ),
)

To show an error state in the event that the QR code can't be validated:

QrImageView(
  data: 'This QR code will show the error state instead',
  version: 1,
  size: 320,
  gapless: false,
  errorStateBuilder: (cxt, err) {
    return Container(
      child: Center(
        child: Text(
          'Uh oh! Something went wrong...',
          textAlign: TextAlign.center,
        ),
      ),
    );
  },
)

Outro

Credits

Thanks to Kevin Moore for his awesome QR - Dart library. It's the core of this library.

For author/contributor information, see the AUTHORS file.

License

QR.Flutter is released under a BSD-3 license. See LICENSE for details.

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add qr_flutter

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  qr_flutter: ^4.1.0

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

Import it

Now in your Dart code, you can use:

import 'package:qr_flutter/qr_flutter.dart';

example/lib/main.dart

/*
 * QR.Flutter
 * Copyright (c) 2019 the QR.Flutter authors.
 * See LICENSE for distribution and usage details.
 */

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

import 'main_screen.dart';

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

/// The example application class
class ExampleApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(
      const SystemUiOverlayStyle(
        statusBarColor: Colors.white,
        statusBarIconBrightness: Brightness.dark,
        systemNavigationBarColor: Colors.white,
        systemNavigationBarIconBrightness: Brightness.dark,
      ),
    );
    return MaterialApp(
      title: 'QR.Flutter',
      theme: ThemeData.light(),
      debugShowCheckedModeBanner: false,
      home: MainScreen(),
    );
  }
}

Download details:

Author: theyakka.com

Source: https://github.com/theyakka/qr.flutter

#flutter #android #ios #mobile #qr 

QR.Flutter Is A Flutter Library for Simple and Fast QR Code
4.10 GEEK