dashboard/app/lib/app/scanner.dart
bashynx fb3c01cdd7 dashPi: a self-hosted home dashboard, its sync server and phone app
The dashboard (Raspberry Pi 3.5" screen + web pages), the end-to-end
encrypted sync mailbox (PHP + SQLite) and the Android companion app
(Flutter), with docs, clean-install checks and screenshots made from
demo data.

Built mostly with an AI coding assistant; not yet reviewed line by line
by a human (see README and SECURITY.md).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 09:56:19 +02:00

43 lines
1.6 KiB
Dart

// The camera, until a code is read: ZXing (flutter_zxing: open source, on the phone — no Google services)
// over Flutter's camera plugin. The food barcodes (health/food_archive.dart) and the connect screen's QR
// code from the dashboard's Settings ▸ General ▸ Sync (main.dart).
import 'package:flutter/material.dart';
import 'package:flutter_zxing/flutter_zxing.dart';
/// → the code's text once `accept` takes it, or null (closed).
Future<String?> scanCode(BuildContext context,
{required String title, required int format, required bool Function(String) accept}) =>
Navigator.of(context).push<String>(MaterialPageRoute(
builder: (_) => _Scanner(title: title, format: format, accept: accept), fullscreenDialog: true));
class _Scanner extends StatefulWidget {
const _Scanner({required this.title, required this.format, required this.accept});
final String title;
final int format;
final bool Function(String) accept;
@override
State<_Scanner> createState() => _ScannerState();
}
class _ScannerState extends State<_Scanner> {
bool done = false;
@override
Widget build(BuildContext context) => Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(title: Text(widget.title)),
body: ReaderWidget(
codeFormat: widget.format,
tryHarder: true,
showGallery: false,
showToggleCamera: false,
scanDelay: const Duration(milliseconds: 300),
onScan: (code) {
final v = code.text;
if (done || !code.isValid || v == null || !widget.accept(v)) return;
done = true;
Navigator.of(context).pop(v);
},
),
);
}