Merge pull request #752 from cake-tech/receive-screen-issue

CW-284 Fix QR code UI and logic issues
This commit is contained in:
Omar Hatem 2023-01-31 19:10:53 +02:00 committed by GitHub
commit 61050ac715
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 86 deletions

View file

@ -165,14 +165,7 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
.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)
]),

View file

@ -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),
),
),
),

View file

@ -1,30 +1,29 @@
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 = 9, // Previous value: 7 something happened after flutter upgrade monero wallets addresses are longer than ver. 7 ???
int errorCorrectionLevel = QrErrorCorrectLevel.L,
}) : _painter = QrPainter(data, foregroundColor, version, errorCorrectionLevel);
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;
@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: Colors.black,
backgroundColor: Colors.white,
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

@ -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()),
),
),
),

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: