qr_code_scanner:用的最多的扫码库,也支持开关灯,作用不错引荐,不过其默许在ios端为swift代码,原生默许为Object-c的需求桥接

qr_flutter:一款不错的二维码生成东西,经过传递字符串能够直接生成 Widget

flutter-scankit:华为的扫码库,关于一些小的、有损坏、污点的二维码,有扫描优化,唯一的缺陷便是库太老,除了事例,其他项目基本上用不了直接报错,如果能解决报错仍是引荐的,个人比较懒,就不解决了^_^

qr_code_scanner扫码

qr_code_scanner

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
class ScanPage extends StatefulWidget {
  final Function(Barcode? result)? completed;
  const ScanPage({Key? key, this.completed,}) : super(key: key);
  @override
  State<ScanPage> createState() => _ScanPageState();
}
class _ScanPageState extends State<ScanPage> {
  final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
  QRViewController? _controller;
  @override
  void reassemble() {
    super.reassemble();
    _controller?.resumeCamera();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color.fromRGBO(0, 0, 0, 0.7), //默许颜色,太白了不好看
      body: Stack(
        children: [
          QRView(
            key: qrKey,
            onQRViewCreated: _onQRViewCreated,
          ),
          Positioned(
            bottom: 60,
            left: 0,
            right: 0,
            child: SafeArea(
              child: CupertinoButton(
                onPressed: () {
                  _controller?.toggleFlash();
                },
                child: Container(
                  alignment: Alignment.center,
                  height: 64,
                  child: Image.asset('images/flash_light.png'),
                ),
              ),
            ),
          ),
          SafeArea(
            child: GestureDetector(
              onTap: () {
                Navigator.of(context).pop();
              },
              child: const SizedBox(
                width: 60,
                height: 44,
                child: Icon(
                  Icons.arrow_back_ios_new,
                  color: Colors.white,
                  size: 26,
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
  void _onQRViewCreated(QRViewController controller) {
    _controller = controller;
    controller.scannedDataStream.listen((result) {
      //print(result.code);
      _controller!.stopCamera();
      Navigator.of(context).pop();
      if (widget.completed != null) {
        widget.completed!(result);
      }
    });
  }
  @override
  void dispose() {
    _controller!.dispose();
    super.dispose();
  }
}

qr_flutter生成二维码

qr_flutter

QrImage(
  data: "1234567890", //数据
  //二维码版别,二维码有很多个版别,不同版别会有所不同,可能会影响一些或者扫描库扫描,碰到问题能够切换版别
  version: QrVersions.auto,
  size: 200.0, //大小
),
QrImage(
  data: 'This QR code will show the error state instead',
  version: 1,
  size: 320,
  gapless: false, //无空隙二维码
  //生成失利后的widget显示
  errorStateBuilder: (cxt, err) {
    return Container(
      child: Center(
        child: Text(
          "Uh oh! Something went wrong...",
          textAlign: TextAlign.center,
        ),
      ),
    );
  },
)