1. Import dependencies
In the pubspec.yaml file, add dependencies and execute the flutter pub get command
# 二维码
qr_flutter: ^4.0.0
Attributes | type | describe |
---|---|---|
version | int | QrVersions.auto or a value between 1 and 40 |
errorCorrectionLevel | int | value QrErrorCorrectLevel . For example: QrErrorCorrectLevel.L . |
size | double | Image (square) size. If not assigned a value will be automatically resized using the minimum size constraint. |
padding | EdgeInsets | QR code padding |
backgroundColor | Color | background color, default none |
foregroundColor | Color | Foreground color, default is black |
gapless | bool | Add an extra pixel to prevent gaps (default true) |
errorStateBuilder | QrErrorBuilder | Widget Allows you to display an error status when an error occurs while rendering the QR code (for example: version too low, input too long, etc.). |
constrainErrorBounds | bool | If true, errors Widget will be limited to the square where the QR code is drawn. If false, the error state Widget will grow/shrink to whatever size it needs. |
embeddedImage | ImageProvider | Image overlaid in the center of the QR code |
embeddedImageStyle | QrEmbeddedImageStyle | Style embedded images |
embeddedImageEmitsError | bool | If true, any failure to load an embedded image will trigger errorStateBuilder or render an empty one Container . If false, the QR code will be rendered and the embedded image will be ignored. |
semanticsLabel | String | semanticsLabel Will be used by screen readers to describe the content of the QR code. |
2. Import the header file
import 'package:qr_flutter/qr_flutter.dart';
3. Use
Container(
width: getScreenWidth(),
alignment: Alignment.topCenter,
child: QrImage(
padding: EdgeInsets.all(20),//边框
data: 'This QR code will show the error state instead',//二维码携带信息
size: 200,//二维码大小
backgroundColor: Colors.white,//背景色
foregroundColor: Colors.black,//绘制方块颜色
embeddedImage: AssetImage('assets/images/order/order_activity.png'),//二维码中心图片
embeddedImageStyle: QrEmbeddedImageStyle(
//中心图片大小
size: Size(40, 40),
),
),
)
actual effect: