From 4353e778bb7b949c5ae23e825dd558b30de2c682 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Sat, 28 Jan 2023 15:47:44 +0200 Subject: [PATCH 1/3] Increase QR version to support longer addresses --- lib/src/screens/receive/widgets/qr_image.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/screens/receive/widgets/qr_image.dart b/lib/src/screens/receive/widgets/qr_image.dart index c0c1b0666..9e33080e0 100644 --- a/lib/src/screens/receive/widgets/qr_image.dart +++ b/lib/src/screens/receive/widgets/qr_image.dart @@ -8,7 +8,7 @@ class QrImage extends StatelessWidget { this.size = 100.0, this.backgroundColor, Color foregroundColor = Colors.black, - int version = 9, // Previous value: 7 something happened after flutter upgrade monero wallets addresses are longer than ver. 7 ??? + 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); From 425914ade3a04648229c1c045b4b9709046ecbc8 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Mon, 30 Jan 2023 20:03:47 +0200 Subject: [PATCH 2/3] - 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: From 0e9d30c915b5295c600b5b5d468dd41a1fd179f6 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Tue, 31 Jan 2023 17:31:42 +0200 Subject: [PATCH 3/3] Fixate QR background and foreground colors in all themes --- lib/src/screens/exchange_trade/exchange_trade_page.dart | 9 +-------- lib/src/screens/receive/fullscreen_qr_page.dart | 9 ++------- lib/src/screens/receive/widgets/qr_image.dart | 7 ++----- lib/src/screens/receive/widgets/qr_widget.dart | 6 +----- 4 files changed, 6 insertions(+), 25 deletions(-) diff --git a/lib/src/screens/exchange_trade/exchange_trade_page.dart b/lib/src/screens/exchange_trade/exchange_trade_page.dart index 5aacf3f1f..1fe4983f6 100644 --- a/lib/src/screens/exchange_trade/exchange_trade_page.dart +++ b/lib/src/screens/exchange_trade/exchange_trade_page.dart @@ -165,14 +165,7 @@ class ExchangeTradeState extends State { .color! ) ), - child: QrImage( - data: trade.inputAddress ?? fetchingLabel, - backgroundColor: Colors.transparent, - foregroundColor: Theme.of(context) - .accentTextTheme! - .subtitle2! - .color!, - ), + child: QrImage(data: trade.inputAddress ?? fetchingLabel), )))), Spacer(flex: 3) ]), diff --git a/lib/src/screens/receive/fullscreen_qr_page.dart b/lib/src/screens/receive/fullscreen_qr_page.dart index 165adff12..0966c8ac8 100644 --- a/lib/src/screens/receive/fullscreen_qr_page.dart +++ b/lib/src/screens/receive/fullscreen_qr_page.dart @@ -1,7 +1,6 @@ import 'package:cake_wallet/src/screens/receive/widgets/qr_image.dart'; import 'package:cake_wallet/themes/theme_base.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/cupertino.dart'; import 'package:cake_wallet/src/screens/base_page.dart'; class FullscreenQRPage extends BasePage { @@ -69,14 +68,10 @@ class FullscreenQRPage extends BasePage { child: AspectRatio( aspectRatio: 1.0, child: Container( - padding: EdgeInsets.all(5), + padding: EdgeInsets.all(10), decoration: BoxDecoration( border: Border.all(width: 3, color: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!)), - child: QrImage( - data: qrData, - backgroundColor: isLight ? Colors.transparent : Colors.black, - foregroundColor: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!, - ), + child: QrImage(data: qrData), ), ), ), diff --git a/lib/src/screens/receive/widgets/qr_image.dart b/lib/src/screens/receive/widgets/qr_image.dart index 3936f847e..6e17dbcfc 100644 --- a/lib/src/screens/receive/widgets/qr_image.dart +++ b/lib/src/screens/receive/widgets/qr_image.dart @@ -5,18 +5,14 @@ class QrImage extends StatelessWidget { QrImage({ required this.data, this.size = 100.0, - this.backgroundColor, - 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 Color? backgroundColor; final double size; final String data; final int version; final int errorCorrectionLevel; - final Color foregroundColor; @override Widget build(BuildContext context) { @@ -25,7 +21,8 @@ class QrImage extends StatelessWidget { errorCorrectionLevel: errorCorrectionLevel, version: version, size: size, - foregroundColor: foregroundColor, + foregroundColor: Colors.black, + backgroundColor: Colors.white, padding: EdgeInsets.zero, ); } diff --git a/lib/src/screens/receive/widgets/qr_widget.dart b/lib/src/screens/receive/widgets/qr_widget.dart index 99bea1adc..a590293a6 100644 --- a/lib/src/screens/receive/widgets/qr_widget.dart +++ b/lib/src/screens/receive/widgets/qr_widget.dart @@ -89,11 +89,7 @@ class QRWidget extends StatelessWidget { color: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!, ), ), - child: QrImage( - data: addressListViewModel.uri.toString(), - backgroundColor: isLight ? Colors.transparent : Colors.black, - foregroundColor: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!, - ), + child: QrImage(data: addressListViewModel.uri.toString()), ), ), ),