feat(#674): tell the owner when a contact sync comes up short

A short contact sync is now loud (SAFELANE 6). A banner above the whole
app says the radio reported N contacts but sent M and that the saved
contacts were kept; it stays until dismissed. When the automatic retry
is short too, a modal asks: Keep my contacts (the default, focused, so
Enter keeps) or Use the radio's list, which states how many contacts it
would remove. Owner decisions on #670.

The banner sits in MaterialApp.builder next to the storage banner
(#385), above the Navigator, so the modal is drawn in place rather than
pushed as a route. Strings are English; other locales fall back through
untranslated.json, as the storage banner's do.

Widget tests cover hidden, shown with counts, the no-total wording,
dismiss, the decision's default and both choices; with the Keep default
removed, two fail.

Epic #668.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
feat/668-contact-sync-guard
Strycher 2 months ago committed by diffwireauto
parent 9a43fde09f
commit e5c7a27fdf

@ -3086,5 +3086,54 @@
"settings_configBackupSubtitle": "Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.",
"@settings_configBackupSubtitle": {
"description": "Explains what the config export and import entries do (#568)."
},
"contactSyncShortfallTitle": "Contact sync incomplete",
"@contactSyncShortfallTitle": {
"description": "Persistent banner title when the radio sent fewer contacts than it reported (#668)."
},
"contactSyncShortfallBody": "The radio reported {declared} contacts but sent {received}. Your saved contacts were kept.",
"@contactSyncShortfallBody": {
"description": "Persistent banner body for a short contact sync (#668).",
"placeholders": {
"declared": {
"type": "int"
},
"received": {
"type": "int"
}
}
},
"contactSyncShortfallBodyNoTotal": "The radio did not report how many contacts it holds and sent {received}. Your saved contacts were kept.",
"@contactSyncShortfallBodyNoTotal": {
"description": "Persistent banner body for a contact sync whose total the radio did not report (#668).",
"placeholders": {
"received": {
"type": "int"
}
}
},
"contactSyncDecisionTitle": "Contact sync still incomplete",
"@contactSyncDecisionTitle": {
"description": "Dialog title after the automatic retry of a short contact sync was also short (#668)."
},
"contactSyncDecisionBody": "The radio sent only {received} contacts again. Keep your saved contacts, or use the radio's list? Using the radio's list removes {removed} contacts from this app.",
"@contactSyncDecisionBody": {
"description": "Dialog body asking whether to keep saved contacts or accept the radio's shorter list (#668).",
"placeholders": {
"received": {
"type": "int"
},
"removed": {
"type": "int"
}
}
},
"contactSyncKeep": "Keep my contacts",
"@contactSyncKeep": {
"description": "Default dialog action: keep the saved contact list after a short sync (#668)."
},
"contactSyncUseRadio": "Use the radio's list",
"@contactSyncUseRadio": {
"description": "Dialog action: replace the saved contacts with the radio's shorter list (#668)."
}
}

@ -8829,6 +8829,48 @@ abstract class AppLocalizations {
/// In en, this message translates to:
/// **'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.'**
String get settings_configBackupSubtitle;
/// Persistent banner title when the radio sent fewer contacts than it reported (#668).
///
/// In en, this message translates to:
/// **'Contact sync incomplete'**
String get contactSyncShortfallTitle;
/// Persistent banner body for a short contact sync (#668).
///
/// In en, this message translates to:
/// **'The radio reported {declared} contacts but sent {received}. Your saved contacts were kept.'**
String contactSyncShortfallBody(int declared, int received);
/// Persistent banner body for a contact sync whose total the radio did not report (#668).
///
/// In en, this message translates to:
/// **'The radio did not report how many contacts it holds and sent {received}. Your saved contacts were kept.'**
String contactSyncShortfallBodyNoTotal(int received);
/// Dialog title after the automatic retry of a short contact sync was also short (#668).
///
/// In en, this message translates to:
/// **'Contact sync still incomplete'**
String get contactSyncDecisionTitle;
/// Dialog body asking whether to keep saved contacts or accept the radio's shorter list (#668).
///
/// In en, this message translates to:
/// **'The radio sent only {received} contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes {removed} contacts from this app.'**
String contactSyncDecisionBody(int received, int removed);
/// Default dialog action: keep the saved contact list after a short sync (#668).
///
/// In en, this message translates to:
/// **'Keep my contacts'**
String get contactSyncKeep;
/// Dialog action: replace the saved contacts with the radio's shorter list (#668).
///
/// In en, this message translates to:
/// **'Use the radio\'s list'**
String get contactSyncUseRadio;
}
class _AppLocalizationsDelegate

@ -5198,4 +5198,31 @@ class AppLocalizationsBg extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -5215,4 +5215,31 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -5121,4 +5121,31 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -5203,4 +5203,31 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -5231,4 +5231,31 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -5220,4 +5220,31 @@ class AppLocalizationsHu extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -5208,4 +5208,31 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -4974,4 +4974,31 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -4975,4 +4975,31 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -5183,4 +5183,31 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -5220,4 +5220,31 @@ class AppLocalizationsPl extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -5196,4 +5196,31 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -5214,4 +5214,31 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -5180,4 +5180,31 @@ class AppLocalizationsSk extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -5178,4 +5178,31 @@ class AppLocalizationsSl extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -5153,4 +5153,31 @@ class AppLocalizationsSv extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -5215,4 +5215,31 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -4848,4 +4848,31 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get settings_configBackupSubtitle =>
'Back up or restore contacts, channels, radio settings and identity, in the MeshCore stock format.';
@override
String get contactSyncShortfallTitle => 'Contact sync incomplete';
@override
String contactSyncShortfallBody(int declared, int received) {
return 'The radio reported $declared contacts but sent $received. Your saved contacts were kept.';
}
@override
String contactSyncShortfallBodyNoTotal(int received) {
return 'The radio did not report how many contacts it holds and sent $received. Your saved contacts were kept.';
}
@override
String get contactSyncDecisionTitle => 'Contact sync still incomplete';
@override
String contactSyncDecisionBody(int received, int removed) {
return 'The radio sent only $received contacts again. Keep your saved contacts, or use the radio\'s list? Using the radio\'s list removes $removed contacts from this app.';
}
@override
String get contactSyncKeep => 'Keep my contacts';
@override
String get contactSyncUseRadio => 'Use the radio\'s list';
}

@ -31,6 +31,7 @@ import 'services/window_geometry_service.dart';
import 'services/store_consolidation_service.dart';
import 'services/storage_health_service.dart';
import 'storage/drift/blob_store.dart';
import 'widgets/contact_sync_shortfall_banner.dart';
import 'widgets/storage_unavailable_banner.dart';
import 'storage/prefs_manager.dart';
import 'utils/app_logger.dart';
@ -284,7 +285,20 @@ class MeshCoreApp extends StatelessWidget {
child: Consumer<StorageHealthService>(
builder: (context, health, _) => StorageUnavailableBanner(
show: !health.available,
child: child ?? const SizedBox.shrink(),
child: Consumer<MeshCoreConnector>(
builder: (context, connector, _) =>
ContactSyncShortfallBanner(
shortfall: connector.contactSyncShortfall,
decisionPending:
connector.contactSyncDecisionPending,
undeliveredCount:
connector.contactSyncUndeliveredCount,
onDismiss: connector.dismissContactSyncShortfall,
onKeep: connector.resolveContactSyncKeepLocal,
onUseRadio: connector.resolveContactSyncUseRadio,
child: child ?? const SizedBox.shrink(),
),
),
),
),
),

@ -0,0 +1,125 @@
import 'package:flutter/material.dart';
import '../connector/meshcore_connector.dart';
import '../l10n/l10n.dart';
/// Shown above the whole app when a full contact sync delivered fewer contacts
/// than the radio reported (#668). The banner stays until dismissed. When the
/// automatic retry was also short, a modal asks whether to keep the saved
/// contacts (the default) or accept the radio's shorter list.
///
/// SAFELANE §6: the short sync that silently replaced 350 saved contacts with
/// 106 (#660) must now be loud. Sits in `MaterialApp.builder`, above the
/// Navigator, so the modal is drawn here rather than pushed as a route.
class ContactSyncShortfallBanner extends StatelessWidget {
final ContactSyncShortfall? shortfall;
final bool decisionPending;
final int undeliveredCount;
final VoidCallback onDismiss;
final VoidCallback onKeep;
final VoidCallback onUseRadio;
final Widget child;
const ContactSyncShortfallBanner({
super.key,
required this.shortfall,
required this.decisionPending,
required this.undeliveredCount,
required this.onDismiss,
required this.onKeep,
required this.onUseRadio,
required this.child,
});
@override
Widget build(BuildContext context) {
final current = shortfall;
if (current == null && !decisionPending) return child;
final content = current == null
? child
: Column(
children: [
_banner(context, current),
Expanded(child: child),
],
);
if (!decisionPending) return content;
return Stack(
children: [
content,
const ModalBarrier(dismissible: false, color: Colors.black54),
Center(child: _decision(context, current?.received ?? 0)),
],
);
}
Widget _banner(BuildContext context, ContactSyncShortfall current) {
final l10n = context.l10n;
final scheme = Theme.of(context).colorScheme;
final declared = current.declared;
final body = declared == null
? l10n.contactSyncShortfallBodyNoTotal(current.received)
: l10n.contactSyncShortfallBody(declared, current.received);
return Material(
color: scheme.errorContainer,
child: SafeArea(
bottom: false,
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 10, 4, 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(Icons.sync_problem, color: scheme.onErrorContainer),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
l10n.contactSyncShortfallTitle,
style: TextStyle(
fontWeight: FontWeight.bold,
color: scheme.onErrorContainer,
),
),
const SizedBox(height: 2),
Text(
body,
style: TextStyle(color: scheme.onErrorContainer),
),
],
),
),
IconButton(
tooltip: l10n.common_close,
icon: Icon(Icons.close, color: scheme.onErrorContainer),
onPressed: onDismiss,
),
],
),
),
),
);
}
Widget _decision(BuildContext context, int received) {
final l10n = context.l10n;
return AlertDialog(
title: Text(l10n.contactSyncDecisionTitle),
content: Text(l10n.contactSyncDecisionBody(received, undeliveredCount)),
actions: [
TextButton(
onPressed: onUseRadio,
child: Text(l10n.contactSyncUseRadio),
),
FilledButton(
autofocus: true,
onPressed: onKeep,
child: Text(l10n.contactSyncKeep),
),
],
);
}
}

@ -0,0 +1,119 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/connector/meshcore_connector.dart';
import 'package:meshcore_open/l10n/app_localizations.dart';
import 'package:meshcore_open/widgets/contact_sync_shortfall_banner.dart';
/// #674: a short contact sync must be loud and stay visible, and the choice
/// after a failed retry must default to keeping the saved contacts.
void main() {
late List<String> calls;
Widget build({
ContactSyncShortfall? shortfall,
bool decisionPending = false,
int undelivered = 244,
}) => MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: ContactSyncShortfallBanner(
shortfall: shortfall,
decisionPending: decisionPending,
undeliveredCount: undelivered,
onDismiss: () => calls.add('dismiss'),
onKeep: () => calls.add('keep'),
onUseRadio: () => calls.add('useRadio'),
child: const Text('APP'),
),
),
);
const short = ContactSyncShortfall(
declared: 350,
received: 106,
keptLocally: 244,
);
setUp(() => calls = []);
testWidgets('no shortfall: only the app renders', (tester) async {
await tester.pumpWidget(build());
expect(find.text('APP'), findsOneWidget);
expect(find.text('Contact sync incomplete'), findsNothing);
});
testWidgets('shortfall: banner with the counts, above the app', (
tester,
) async {
await tester.pumpWidget(build(shortfall: short));
expect(find.text('Contact sync incomplete'), findsOneWidget);
expect(
find.textContaining('reported 350 contacts but sent 106'),
findsOneWidget,
);
expect(find.text('APP'), findsOneWidget);
expect(find.byType(AlertDialog), findsNothing);
});
testWidgets('no declared total uses its own wording', (tester) async {
await tester.pumpWidget(
build(
shortfall: const ContactSyncShortfall(
declared: null,
received: 50,
keptLocally: 3,
),
),
);
expect(find.textContaining('did not report how many'), findsOneWidget);
});
testWidgets('the close button dismisses', (tester) async {
await tester.pumpWidget(build(shortfall: short));
await tester.tap(find.byIcon(Icons.close));
expect(calls, ['dismiss']);
});
group('decision pending', () {
testWidgets('asks, says how many would be removed, defaults to Keep', (
tester,
) async {
await tester.pumpWidget(build(shortfall: short, decisionPending: true));
await tester.pump();
expect(find.byType(AlertDialog), findsOneWidget);
expect(find.textContaining('removes 244 contacts'), findsOneWidget);
final keep = tester.widget<FilledButton>(find.byType(FilledButton));
expect(keep.autofocus, isTrue);
expect(find.text('Keep my contacts'), findsOneWidget);
});
testWidgets('Keep my contacts', (tester) async {
await tester.pumpWidget(build(shortfall: short, decisionPending: true));
await tester.tap(find.text('Keep my contacts'));
expect(calls, ['keep']);
});
testWidgets('Use the radio\'s list', (tester) async {
await tester.pumpWidget(build(shortfall: short, decisionPending: true));
await tester.tap(find.text('Use the radio\'s list'));
expect(calls, ['useRadio']);
});
testWidgets('Enter on the dialog picks the default, Keep', (tester) async {
await tester.pumpWidget(build(shortfall: short, decisionPending: true));
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
expect(calls, ['keep']);
});
});
}

@ -206,7 +206,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"de": [
@ -416,7 +423,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"es": [
@ -626,7 +640,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"fr": [
@ -836,7 +857,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"hu": [
@ -1046,7 +1074,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"it": [
@ -1256,7 +1291,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"ja": [
@ -1466,7 +1508,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"ko": [
@ -1676,7 +1725,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"nl": [
@ -1886,7 +1942,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"pl": [
@ -2096,7 +2159,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"pt": [
@ -2306,7 +2376,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"ru": [
@ -2516,7 +2593,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"sk": [
@ -2726,7 +2810,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"sl": [
@ -2936,7 +3027,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"sv": [
@ -3146,7 +3244,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"uk": [
@ -3356,7 +3461,14 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
],
"zh": [
@ -3566,6 +3678,13 @@
"importConfig_close",
"settings_exportConfig",
"settings_importConfig",
"settings_configBackupSubtitle"
"settings_configBackupSubtitle",
"contactSyncShortfallTitle",
"contactSyncShortfallBody",
"contactSyncShortfallBodyNoTotal",
"contactSyncDecisionTitle",
"contactSyncDecisionBody",
"contactSyncKeep",
"contactSyncUseRadio"
]
}

Loading…
Cancel
Save

Powered by TurnKey Linux.