- Replace QR package with another reade made one to exclude error being from painting QR

- Revert QR version change so its re-producible if it happens again
This commit is contained in:
OmarHatem 2023-01-30 20:03:47 +02:00
parent 4353e778bb
commit 425914ade3
3 changed files with 19 additions and 64 deletions

View file

@ -1,30 +1,32 @@
import 'package:flutter/material.dart';
import 'package:qr/qr.dart';
import 'package:cake_wallet/src/screens/receive/widgets/qr_painter.dart';
import 'package:qr_flutter/qr_flutter.dart' as qr;
class QrImage extends StatelessWidget {
QrImage({
required String data,
required this.data,
this.size = 100.0,
this.backgroundColor,
Color foregroundColor = Colors.black,
int version = 13, // Previous value: 9 BTC & LTC wallets addresses are longer than ver. 9
int errorCorrectionLevel = QrErrorCorrectLevel.L,
}) : _painter = QrPainter(data, foregroundColor, version, errorCorrectionLevel);
this.foregroundColor = Colors.black,
this.version = 9, // Previous value: 7 something happened after flutter upgrade monero wallets addresses are longer than ver. 7 ???
this.errorCorrectionLevel = qr.QrErrorCorrectLevel.L,
});
final QrPainter _painter;
final Color? backgroundColor;
final double size;
final String data;
final int version;
final int errorCorrectionLevel;
final Color foregroundColor;
@override
Widget build(BuildContext context) {
return Container(
width: size,
height: size,
color: backgroundColor,
child: CustomPaint(
painter: _painter,
),
return qr.QrImage(
data: data,
errorCorrectionLevel: errorCorrectionLevel,
version: version,
size: size,
foregroundColor: foregroundColor,
padding: EdgeInsets.zero,
);
}
}
}

View file

@ -1,47 +0,0 @@
import 'package:flutter/material.dart';
import 'package:qr/qr.dart';
class QrPainter extends CustomPainter {
QrPainter(
String data,
this.color,
this.version,
this.errorCorrectionLevel,
) : this._qr = QrCode(version, errorCorrectionLevel)..addData(data) {
_p.color = this.color;
_qrImage = QrImage(_qr);
}
final int version;
final int errorCorrectionLevel;
final Color color;
final QrCode _qr;
final _p = Paint()..style = PaintingStyle.fill;
late QrImage _qrImage;
@override
void paint(Canvas canvas, Size size) {
final squareSize = size.shortestSide / _qr.moduleCount;
for (int x = 0; x < _qr.moduleCount; x++) {
for (int y = 0; y < _qr.moduleCount; y++) {
if (_qrImage.isDark(y, x)) {
final squareRect = Rect.fromLTWH(
x * squareSize, y * squareSize, squareSize, squareSize);
canvas.drawRect(squareRect, _p);
}
}
}
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
if (oldDelegate is QrPainter) {
return this.color != oldDelegate.color ||
this.errorCorrectionLevel != oldDelegate.errorCorrectionLevel ||
this.version != oldDelegate.version;
}
return false;
}
}

View file

@ -6,7 +6,7 @@ dependencies:
flutter_cupertino_localizations: ^1.0.1
intl: ^0.17.0
url_launcher: ^6.1.4
qr: ^3.0.1
qr_flutter: ^4.0.0
uuid: 3.0.6
shared_preferences: ^2.0.15
flutter_secure_storage: