diff --git a/apps/app_seeds/lib/ui/profile_screen.dart b/apps/app_seeds/lib/ui/profile_screen.dart index 02cbb32..56f0141 100644 --- a/apps/app_seeds/lib/ui/profile_screen.dart +++ b/apps/app_seeds/lib/ui/profile_screen.dart @@ -5,6 +5,7 @@ import '../i18n/strings.g.dart'; import '../services/profile_store.dart'; import '../services/social_service.dart'; import '../services/social_settings.dart'; +import 'qr_view.dart'; import 'theme.dart'; /// Your own profile: the shareable identity (npub) plus a display name and short @@ -164,7 +165,9 @@ class _IdentityCard extends StatelessWidget { t.profile.idHelp, style: const TextStyle(color: seedMuted, fontSize: 12), ), - const SizedBox(height: 10), + const SizedBox(height: 14), + Center(child: QrView(data: npub, size: 200)), + const SizedBox(height: 12), SelectableText( npub, style: const TextStyle( diff --git a/apps/app_seeds/lib/ui/qr_view.dart b/apps/app_seeds/lib/ui/qr_view.dart new file mode 100644 index 0000000..970f4ea --- /dev/null +++ b/apps/app_seeds/lib/ui/qr_view.dart @@ -0,0 +1,54 @@ +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; +} diff --git a/apps/app_seeds/pubspec.yaml b/apps/app_seeds/pubspec.yaml index 7409d24..ad6dc3f 100644 --- a/apps/app_seeds/pubspec.yaml +++ b/apps/app_seeds/pubspec.yaml @@ -57,6 +57,9 @@ dependencies: # Pure-Dart PDF generation (Apache-2.0) for the printable "what I share" # catalog. No platform channels, so the whole flow is host-testable. pdf: ^3.11.3 + # Pure-Dart barcode/QR generation (Apache-2.0; already used transitively by + # pdf). Painted on screen for the profile's shareable identity QR. + barcode: ^2.2.9 path: ^1.9.0 path_provider: ^2.1.5