fix:修复门铃码保存后是黑色图片问题

This commit is contained in:
Liuyf 2025-02-19 16:01:58 +08:00
parent 460ca1e2e2
commit 148541bcb2

View File

@ -2,6 +2,7 @@ import 'dart:typed_data';
import 'dart:ui';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
@ -54,7 +55,7 @@ class ShowCupertinoAlertView {
child: Text(
'${"开启微信接收报警消息需要先关注".tr}$qrCodeText${"微信公众号,请保存二维码并使用微信扫一扫设置".tr}',
style:
TextStyle(fontSize: 24.sp, color: Colors.black),
TextStyle(fontSize: 24.sp, color: Colors.black),
)),
SizedBox(
height: 60.h,
@ -159,8 +160,8 @@ class ShowCupertinoAlertView {
//
void realNameIDCardInfoComfirmAlert(
{required String getNameStr,
required String getIDCardStr,
required VoidCallback onConfirm}) {
required String getIDCardStr,
required VoidCallback onConfirm}) {
showCupertinoDialog(
context: Get.context!,
builder: (context) {
@ -340,7 +341,7 @@ class ShowCupertinoAlertView {
),
CupertinoDialogAction(
child:
Text('购买'.tr, style: TextStyle(color: AppColors.mainColor)),
Text('购买'.tr, style: TextStyle(color: AppColors.mainColor)),
onPressed: () {
Get.back();
sureClick();
@ -391,7 +392,7 @@ class ShowCupertinoAlertView {
),
CupertinoDialogAction(
child:
Text('删除'.tr, style: TextStyle(color: AppColors.mainColor)),
Text('删除'.tr, style: TextStyle(color: AppColors.mainColor)),
onPressed: () {
Get.back();
clearClick();
@ -406,8 +407,8 @@ class ShowCupertinoAlertView {
//
void showVisualDoorbellCodeAlert(
{required BuildContext widgetContext,
required String qrCodeUrl,
required String qrCodeText}) {
required String qrCodeUrl,
required String qrCodeText}) {
showCupertinoModalPopup(
context: widgetContext,
builder: (BuildContext context) {
@ -447,7 +448,7 @@ class ShowCupertinoAlertView {
child: Text(
qrCodeText,
style:
TextStyle(fontSize: 24.sp, color: Colors.black),
TextStyle(fontSize: 24.sp, color: Colors.black),
)),
Container(
margin: EdgeInsets.only(left: 60.w, right: 60.w),
@ -456,29 +457,33 @@ class ShowCupertinoAlertView {
onClick: () async {
//
try {
final Color qrcodeStyleColor =
defaultTargetPlatform == TargetPlatform.iOS
? const Color(0xFF000000)
: Colors.white;
final QrPainter painter = QrPainter(
data: qrCodeUrl,
version: QrVersions.auto,
gapless: false,
errorCorrectionLevel: QrErrorCorrectLevel.L,
eyeStyle: const QrEyeStyle(
eyeStyle: QrEyeStyle(
eyeShape: QrEyeShape.square,
color: Colors.white,
color: qrcodeStyleColor,
),
dataModuleStyle: const QrDataModuleStyle(
dataModuleStyle: QrDataModuleStyle(
dataModuleShape: QrDataModuleShape.square,
color: Colors.white,
color: qrcodeStyleColor,
));
final ByteData? byteData =
await painter.toImageData(600.0,
format: ImageByteFormat.png);
await painter.toImageData(600.0,
format: ImageByteFormat.png);
final Uint8List pngBytes =
byteData!.buffer.asUint8List();
byteData!.buffer.asUint8List();
final result =
await ImageGallerySaver.saveImage(
Uint8List.fromList(pngBytes),
quality: 100,
name: 'qr_code');
await ImageGallerySaver.saveImage(
Uint8List.fromList(pngBytes),
quality: 100,
name: 'qr_code');
if (result['isSuccess']) {
EasyLoading.showToast('保存成功'.tr);
} else {