QrCode class

Encoded and styled QR symbol with rendering helpers. 已编码且可样式化的 QR 符号,提供渲染辅助方法。

Constructors

QrCode({required String data, int squareSize = defaultSquareSize, int canvasSize = defaultQrCodeSize, int xOffset = defaultXOffset, int yOffset = defaultYOffset, QrCodeColorFunction? colorFn, QrCodeShapeFunction? shapeFn, QrCodeGraphicsFactory? graphicsFactory, ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.low, int? informationDensity, MaskPattern maskPattern = MaskPattern.pattern000, QrCodeHook? doBefore, QrCodeHook? doAfter, ImageProvider<Object>? logoProvider, double? logoWidth, double? logoHeight})
Creates a QrCode from raw data and styling parameters. 根据原始 data 与样式参数创建 QrCode

Properties

canvasSize int
Output canvas side length in pixels. 输出画布边长(像素)。
getter/setter pair
colorFn QrCodeColorFunction
Resolves foreground/background colors per module. 按模块解析前景/背景色。
final
data String
Payload string encoded into the symbol. 编码进符号的载荷字符串。
final
errorCorrectionLevel ErrorCorrectionLevel
Reed–Solomon error correction level for encoding. 编码所用的 RS 纠错等级。
final
graphics QrCodeGraphics
Default graphics buffer for render. render 使用的默认图形缓冲区。
getter/setter pair
graphicsFactory QrCodeGraphicsFactory
Factory for raster backing stores used during render. 渲染时使用的光栅画布工厂。
final
hashCode int
The hash code for this object.
no setterinherited
informationDensity int
QR version (type number, 1–40) used for this symbol. 本符号使用的 QR 版本号(类型号,1–40)。
latefinal
logoDrawHeight int?
Computed logo height used when drawing. 绘制时使用的 Logo 高度。
getter/setter pair
logoDrawWidth int?
Computed logo width used when drawing. 绘制时使用的 Logo 宽度。
getter/setter pair
logoHeight double?
Logo draw height in pixels; defaults to image height. Logo 绘制高度(像素);默认取图片高度。
final
logoProvider ImageProvider<Object>?
Optional center logo image provider. 可选的中心 Logo 图片提供器。
final
logoWidth double?
Logo draw width in pixels; defaults to image width. Logo 绘制宽度(像素);默认取图片宽度。
final
maskPattern MaskPattern
Mask pattern applied during matrix setup. 矩阵设置时应用的掩码图案。
final
qrCodeProcessor QrCodeProcessor
Encoder used to build rawData. 用于构建 rawData 的编码器。
getter/setter pair
rawData QrCodeRawData
Module matrix after encoding. 编码后的模块矩阵。
getter/setter pair
Resolved logo image after prepare. prepare 后解析得到的 Logo 图片。
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shapeFn QrCodeShapeFunction
Draws each module shape (square, circle, rounded, etc.). 绘制各模块形状(方形、圆形、圆角等)。
final
squareSize int
Pixel size of one module in the internal buffer. 内部缓冲区中单个模块的像素尺寸。
getter/setter pair
xOffset int
Horizontal paint offset in pixels. 水平绘制偏移(像素)。
final
yOffset int
Vertical paint offset in pixels. 垂直绘制偏移(像素)。
final

Methods

fitIntoArea(int width, int height) QrCode
Adjusts module and canvas size to fit width x height. 调整模块与画布尺寸以适配 width x height
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
paintOntoCanvas(Canvas canvas, Size size) → void
Paints the QR code into canvas scaled to size without permanently resizing this instance. 将 QR 码绘制到 canvas 并按 size 缩放,不永久改变本实例尺寸。
prepare() Future<void>
Resolves logoProvider for later drawing in render. 解析 logoProvider,供 render 时绘制 Logo。
render({QrCodeGraphics? qrCodeGraphics, int? xOffset, int? yOffset}) QrCodeGraphics
Renders modules into qrCodeGraphics or the default graphics buffer. 将模块渲染到 qrCodeGraphics 或默认 graphics 缓冲区。
renderToBytes({QrCodeGraphics? qrCodeGraphics, int? xOffset, int? yOffset, String format = 'PNG'}) Future<Uint8List>
Renders to encoded image bytes (PNG by default). 渲染为编码后的图片字节(默认 PNG)。
reset() → void
Clears render flags and resets the graphics buffer. 清除渲染标记并重置图形缓冲区。
resize(int size) QrCode
Resizes the internal canvas to size and clears render flags. 将内部画布调整为 size 并清除渲染标记。
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

circles({required String data, QrCodeConfig config = const QrCodeConfig()}) QrCode
Creates a QR code with circular modules. 创建圆形模块的 QR 码。
create({required String data, QrCodeConfig config = const QrCodeConfig()}) QrCode
Builds a QrCode from data and config. 根据 dataconfig 构建 QrCode
custom({required String data, required QrCodeConfig config}) QrCode
Creates a QR code with a custom QrCodeConfig.shapeFunction. 使用自定义 QrCodeConfig.shapeFunction 创建 QR 码。
roundedSquares({required String data, QrCodeConfig config = const QrCodeConfig()}) QrCode
Creates a QR code with rounded-square modules. 创建圆角方形模块的 QR 码。
squares({required String data, QrCodeConfig config = const QrCodeConfig()}) QrCode
Creates a QR code with square modules. 创建方形模块的 QR 码。

Constants

defaultQrCodeSize → const int
Sentinel canvas size; actual size is computed from modules. 画布尺寸哨兵值;实际尺寸由模块数计算。
defaultSquareSize → const int
Default module pixel size used during encoding layout. 编码布局时使用的默认模块像素尺寸。
defaultXOffset → const int
Default horizontal offset when painting. 绘制时的默认水平偏移。
defaultYOffset → const int
Default vertical offset when painting. 绘制时的默认垂直偏移。