From 425914ade3a04648229c1c045b4b9709046ecbc8 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Mon, 30 Jan 2023 20:03:47 +0200 Subject: [PATCH] - 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 --- lib/src/screens/receive/widgets/qr_image.dart | 34 +++++++------- .../screens/receive/widgets/qr_painter.dart | 47 ------------------- pubspec_base.yaml | 2 +- 3 files changed, 19 insertions(+), 64 deletions(-) delete mode 100644 lib/src/screens/receive/widgets/qr_painter.dart diff --git a/lib/src/screens/receive/widgets/qr_image.dart b/lib/src/screens/receive/widgets/qr_image.dart index 9e33080e0..3936f847e 100644 --- a/lib/src/screens/receive/widgets/qr_image.dart +++ b/lib/src/screens/receive/widgets/qr_image.dart @@ -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, ); } -} \ No newline at end of file +} diff --git a/lib/src/screens/receive/widgets/qr_painter.dart b/lib/src/screens/receive/widgets/qr_painter.dart deleted file mode 100644 index e4af59f1a..000000000 --- a/lib/src/screens/receive/widgets/qr_painter.dart +++ /dev/null @@ -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; - } -} diff --git a/pubspec_base.yaml b/pubspec_base.yaml index b37fd519c..2caa9052f 100644 --- a/pubspec_base.yaml +++ b/pubspec_base.yaml @@ -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: