Fix QR contact import replay guard, type fallback and rescan loops
- Pass the existing contact's advert timestamp (0 for new contacts) so the firmware replay guard does not drop the node's real adverts. - Leave a missing/invalid QR type unset and fall back to the existing contact's type instead of rewriting repeaters/rooms as Companion. - Show a failed state with Retry instead of reopening the camera, which rescanned the same QR and resent the frame in a loop. - Keep the processing flag set after a successful import so the closing route cannot restart the camera, import again and pop twice.
This commit is contained in:
1 parent
fba97b9628
commit
3c971705bd
5 files changed
+111
-19
No files matched your search
@@ -25,6 +25,10 @@ class ContactQrScannerScreen extends StatefulWidget {
|
||||
class _ContactQrScannerScreenState extends State<ContactQrScannerScreen> {
|
||||
bool _isProcessing = false;
|
||||
|
||||
/// Set after a failed import so the camera does not immediately rescan the
|
||||
/// same QR and resend the frame in a loop.
|
||||
bool _importFailed = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -44,6 +48,8 @@ class _ContactQrScannerScreenState extends State<ContactQrScannerScreen> {
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
: _importFailed
|
||||
? _buildImportFailed(context)
|
||||
: QrScannerWidget(
|
||||
onScanned: (data) => _handleScannedData(data),
|
||||
validator: (data) => parseContactQr(data) != null,
|
||||
@@ -54,6 +60,36 @@ class _ContactQrScannerScreenState extends State<ContactQrScannerScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildImportFailed(BuildContext context) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 64,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
context.l10n.contacts_contactImportFailed,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FilledButton.icon(
|
||||
onPressed: () => setState(() => _importFailed = false),
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: Text(context.l10n.common_retry),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildThemedOverlay(BuildContext context) {
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
@@ -202,6 +238,7 @@ class _ContactQrScannerScreenState extends State<ContactQrScannerScreen> {
|
||||
|
||||
setState(() {
|
||||
_isProcessing = true;
|
||||
_importFailed = false;
|
||||
});
|
||||
|
||||
final scanned = parseContactQr(data);
|
||||
@@ -240,18 +277,14 @@ class _ContactQrScannerScreenState extends State<ContactQrScannerScreen> {
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactImported),
|
||||
);
|
||||
// Keep _isProcessing set: resetting it would restart the camera on a
|
||||
// closing route and let a second detection import and pop again.
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactImportFailed),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isProcessing = false;
|
||||
_importFailed = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user