123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- import 'dart:async';
- import 'dart:ui' as ui;
- import 'package:fis_lib_qrcode/qr_flutter.dart';
- import 'package:fis_lib_qrcode/src/custom_qrcode_builder.dart';
- import 'package:fis_ui/index.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- /// 带logo的二维码
- class VQRCodeWithLogo extends StatefulWidget implements FWidget {
- /// 二维码数据
- final String qrData;
- /// 二维码说明
- final String? codeStatement;
- /// 操作说明
- final String? operationStatement;
- /// 操作回调
- final void Function()? operationSuccessCallback;
- /// 尺寸
- final double size;
- /// logo尺寸
- final double? logoSize;
- final double titleWidth;
- ///带Logo的二维码
- const VQRCodeWithLogo(
- this.qrData, {
- Key? key,
- this.codeStatement = "QRCodeStatement",
- this.operationStatement = "QRCodeOperationStatement",
- this.operationSuccessCallback,
- this.size = 280,
- this.titleWidth = 160,
- this.logoSize,
- }) : super(key: key);
- @override
- _VQRCodeWithLogoState createState() => _VQRCodeWithLogoState();
- }
- class _VQRCodeWithLogoState extends State<VQRCodeWithLogo> {
- @override
- Widget build(BuildContext context) {
- final qrFutureBuilder = CustomFutureBuilder<ui.Image>(
- future: _loadOverlayImage(),
- builder: (ctx, snapshot) {
- final size = widget.size;
- final logoSize = widget.logoSize ?? size / 5;
- if (!snapshot.hasData) {
- return Container(width: size, height: size);
- }
- return CustomPaint(
- size: Size.square(size),
- painter: QrPainter(
- data: widget.qrData,
- version: QrVersions.auto,
- eyeStyle: const QrEyeStyle(
- eyeShape: QrEyeShape.square,
- color: Colors.black,
- ),
- dataModuleStyle: const QrDataModuleStyle(
- dataModuleShape: QrDataModuleShape.square,
- color: Colors.black,
- ),
- embeddedImage: snapshot.data,
- embeddedImageStyle: QrEmbeddedImageStyle(
- size: Size.square(logoSize),
- ),
- ),
- );
- },
- );
- return Material(
- color: Colors.white,
- child: FContainer(
- width: widget.titleWidth,
- child: FColumn(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- qrFutureBuilder,
- FPadding(
- padding: EdgeInsets.symmetric(
- vertical: 8,
- horizontal: 8,
- ).copyWith(
- bottom: 5,
- ),
- child: FText(
- widget.codeStatement!,
- overflow: TextOverflow.ellipsis,
- ),
- ),
- FInk(
- decoration: UnderlineTabIndicator(
- borderSide: BorderSide(color: Colors.blue),
- insets: EdgeInsets.fromLTRB(0, 0, 0, 1)),
- child: FInkWell(
- child: FText(
- widget.operationStatement!,
- style: TextStyle(color: Colors.blue),
- ),
- onTap: () => {
- Clipboard.setData(ClipboardData(text: widget.qrData)),
- widget.operationSuccessCallback?.call()
- },
- ),
- )
- ],
- ),
- ),
- );
- }
- Future<ui.Image> _loadOverlayImage() async {
- final completer = Completer<ui.Image>();
- final byteData = await rootBundle.load('assets/images/flyinsono.png');
- ui.decodeImageFromList(byteData.buffer.asUint8List(), completer.complete);
- return completer.future;
- }
- }
|