tane/apps/app_seeds/lib/ui/qr_view.dart
vjrj 3067d9ca7f feat(block2): QR of your npub in the profile (scan to share at a fair)
Adds a QrView (painted from the pure-Dart 'barcode' matrix — already transitive
via pdf, no native plugin) and shows a QR of your npub on the profile identity
card, so you can hand your identity over with a scan. Analyzer clean.
2026-07-10 13:00:47 +02:00

54 lines
1.3 KiB
Dart

import 'package:barcode/barcode.dart';
import 'package:flutter/material.dart';
/// Renders [data] as a QR code, painted from the pure-Dart `barcode` matrix (no
/// native plugin). Used for the profile's shareable identity — hand your npub to
/// someone at a fair with a scan.
class QrView extends StatelessWidget {
const QrView({required this.data, this.size = 200, super.key});
final String data;
final double size;
@override
Widget build(BuildContext context) {
return Container(
width: size,
height: size,
color: Colors.white,
padding: const EdgeInsets.all(8),
child: CustomPaint(
size: Size.square(size),
painter: _QrPainter(data),
),
);
}
}
class _QrPainter extends CustomPainter {
_QrPainter(this.data);
final String data;
@override
void paint(Canvas canvas, Size size) {
final black = Paint()..color = Colors.black;
for (final element in Barcode.qrCode()
.make(data, width: size.width, height: size.height)) {
if (element is BarcodeBar && element.black) {
canvas.drawRect(
Rect.fromLTWH(
element.left,
element.top,
element.width,
element.height,
),
black,
);
}
}
}
@override
bool shouldRepaint(_QrPainter oldDelegate) => oldDelegate.data != data;
}