2025-06-23 21:32:17 -07:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:mobile_scanner/mobile_scanner.dart';
|
|
|
|
|
|
2025-08-30 06:26:56 -07:00
|
|
|
import 'configuration_service.dart';
|
2025-06-23 21:32:17 -07:00
|
|
|
import 'l10n/app_localizations.dart';
|
|
|
|
|
|
|
|
|
|
class QrCodeScreen extends StatefulWidget {
|
|
|
|
|
const QrCodeScreen({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<QrCodeScreen> createState() => _QrCodeScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _QrCodeScreenState extends State<QrCodeScreen> {
|
|
|
|
|
bool _scanned = false;
|
|
|
|
|
|
|
|
|
|
void _onDetect(BarcodeCapture capture) async {
|
|
|
|
|
if (_scanned) return;
|
|
|
|
|
final barcode = capture.barcodes.first;
|
|
|
|
|
final rawValue = barcode.rawValue;
|
|
|
|
|
if (rawValue == null) return;
|
|
|
|
|
final uri = Uri.tryParse(rawValue);
|
|
|
|
|
if (uri == null || uri.scheme.isEmpty) return;
|
|
|
|
|
_scanned = true;
|
2025-08-30 06:26:56 -07:00
|
|
|
await ConfigurationService.applyUri(uri);
|
2025-06-23 21:32:17 -07:00
|
|
|
if (mounted) Navigator.pop(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
title: Text(AppLocalizations.of(context)!.settingsTitle),
|
|
|
|
|
),
|
|
|
|
|
body: MobileScanner(
|
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
|
onDetect: _onDetect,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|