mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
refactor: Remove unnecessary toast notifications and improve code formatting
This commit is contained in:
@@ -409,18 +409,6 @@ class ContactTile extends StatelessWidget {
|
||||
// Determine if we should use flooding (no path) or direct (has path)
|
||||
final hasPath = contact.hasPath;
|
||||
|
||||
// Show initial notification reflecting the method being used
|
||||
ToastLogger.info(
|
||||
context,
|
||||
hasPath
|
||||
? AppLocalizations.of(
|
||||
context,
|
||||
)!.pingingDirect(contact.displayName)
|
||||
: AppLocalizations.of(
|
||||
context,
|
||||
)!.pingingFlood(contact.displayName),
|
||||
);
|
||||
|
||||
// Use smart ping with automatic fallback
|
||||
final result = await connectionProvider.smartPing(
|
||||
contactPublicKey: contact.publicKey,
|
||||
@@ -440,17 +428,7 @@ class ContactTile extends StatelessWidget {
|
||||
|
||||
// Show final result
|
||||
if (context.mounted) {
|
||||
if (result.success) {
|
||||
ToastLogger.success(
|
||||
context,
|
||||
AppLocalizations.of(context)!.pingSuccessful(
|
||||
contact.displayName,
|
||||
result.retriedWithFlooding
|
||||
? AppLocalizations.of(context)!.viaFloodingFallback
|
||||
: '',
|
||||
),
|
||||
);
|
||||
} else {
|
||||
if (!result.success) {
|
||||
ToastLogger.error(
|
||||
context,
|
||||
AppLocalizations.of(context)!.pingFailed(contact.displayName),
|
||||
@@ -494,12 +472,6 @@ class ContactTile extends StatelessWidget {
|
||||
|
||||
// Switch to map tab using callback
|
||||
onNavigateToMap?.call();
|
||||
} else {
|
||||
// No location available, just show toast
|
||||
ToastLogger.info(
|
||||
context,
|
||||
'Repeater ${contact.displayName} has no location data',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,12 +509,6 @@ class ContactTile extends StatelessWidget {
|
||||
final contactsProvider = context.read<ContactsProvider>();
|
||||
|
||||
try {
|
||||
// Show loading toast
|
||||
ToastLogger.info(
|
||||
context,
|
||||
AppLocalizations.of(context)!.removingContact(contact.displayName),
|
||||
);
|
||||
|
||||
// Remove contact from provider (which will also remove from device)
|
||||
await contactsProvider.removeContact(
|
||||
contact.publicKeyHex,
|
||||
@@ -552,13 +518,6 @@ class ContactTile extends StatelessWidget {
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
ToastLogger.success(
|
||||
context,
|
||||
AppLocalizations.of(context)!.contactRemoved(contact.displayName),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
ToastLogger.error(
|
||||
@@ -830,12 +789,6 @@ class ContactTile extends StatelessWidget {
|
||||
contact.publicKey,
|
||||
zeroHop: true,
|
||||
);
|
||||
ToastLogger.info(
|
||||
context,
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
)!.requestingTelemetry(contact.displayName),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.refresh, size: 18),
|
||||
label: Text(AppLocalizations.of(context)!.refresh),
|
||||
@@ -912,12 +865,6 @@ class ContactTile extends StatelessWidget {
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () {
|
||||
connectionProvider.resetPath(contact.publicKey);
|
||||
ToastLogger.info(
|
||||
context,
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
)!.pathResetInfo(contact.displayName),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.route),
|
||||
label: Text(AppLocalizations.of(context)!.resetPath),
|
||||
|
||||
@@ -73,13 +73,17 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
||||
);
|
||||
|
||||
// Format location text
|
||||
final locationText = '📍 Lat: ${position.latitude.toStringAsFixed(5)}, Lon: ${position.longitude.toStringAsFixed(5)}';
|
||||
final locationText =
|
||||
'📍 Lat: ${position.latitude.toStringAsFixed(5)}, Lon: ${position.longitude.toStringAsFixed(5)}';
|
||||
|
||||
// Check if adding location would exceed limit
|
||||
final currentText = _textController.text;
|
||||
if (currentText.length + locationText.length > _maxCharacters) {
|
||||
if (!mounted) return;
|
||||
ToastLogger.error(context, 'Adding location would exceed 160 character limit');
|
||||
ToastLogger.error(
|
||||
context,
|
||||
'Adding location would exceed 160 character limit',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -94,13 +98,14 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
||||
_textController.text = newText;
|
||||
|
||||
// Move cursor to end of inserted text
|
||||
final newCursorPosition = (selection.start >= 0 ? selection.start : currentText.length) + locationText.length;
|
||||
final newCursorPosition =
|
||||
(selection.start >= 0 ? selection.start : currentText.length) +
|
||||
locationText.length;
|
||||
_textController.selection = TextSelection.fromPosition(
|
||||
TextPosition(offset: newCursorPosition),
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
ToastLogger.success(context, 'Location inserted');
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ToastLogger.error(context, 'Failed to get location: $e');
|
||||
@@ -116,7 +121,10 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
||||
|
||||
if (!connectionProvider.deviceInfo.isConnected) {
|
||||
if (!mounted) return;
|
||||
ToastLogger.error(context, AppLocalizations.of(context)!.notConnectedToDevice);
|
||||
ToastLogger.error(
|
||||
context,
|
||||
AppLocalizations.of(context)!.notConnectedToDevice,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -140,7 +148,8 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
||||
text: text,
|
||||
receivedAt: DateTime.now(),
|
||||
deliveryStatus: MessageDeliveryStatus.sending,
|
||||
recipientPublicKey: widget.contact.publicKey, // Store recipient for retry
|
||||
recipientPublicKey:
|
||||
widget.contact.publicKey, // Store recipient for retry
|
||||
);
|
||||
|
||||
// Add to messages list with "sending" status
|
||||
@@ -174,11 +183,12 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
||||
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context); // Close the dialog
|
||||
|
||||
ToastLogger.success(context, AppLocalizations.of(context)!.directMessageSentTo(widget.contact.displayName));
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ToastLogger.error(context, AppLocalizations.of(context)!.failedToSend(e.toString()));
|
||||
ToastLogger.error(
|
||||
context,
|
||||
AppLocalizations.of(context)!.failedToSend(e.toString()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +213,9 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.surfaceContainerHighest,
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(20),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
@@ -265,12 +277,15 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
||||
),
|
||||
initialZoom: 13.0,
|
||||
interactionOptions: const InteractionOptions(
|
||||
flags: InteractiveFlag.pinchZoom | InteractiveFlag.drag,
|
||||
flags:
|
||||
InteractiveFlag.pinchZoom |
|
||||
InteractiveFlag.drag,
|
||||
),
|
||||
),
|
||||
children: [
|
||||
TileLayer(
|
||||
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
urlTemplate:
|
||||
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
userAgentPackageName: 'com.meshcore.sar',
|
||||
),
|
||||
MarkerLayer(
|
||||
@@ -301,7 +316,11 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.gps_fixed, size: 14, color: colorScheme.onSurfaceVariant),
|
||||
Icon(
|
||||
Icons.gps_fixed,
|
||||
size: 14,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'${contactLocation.latitude.toStringAsFixed(5)}, ${contactLocation.longitude.toStringAsFixed(5)}',
|
||||
@@ -355,7 +374,10 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: colorScheme.primary, width: 2),
|
||||
borderSide: BorderSide(
|
||||
color: colorScheme.primary,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(16),
|
||||
counterText: '', // Hide default counter
|
||||
@@ -365,7 +387,10 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
||||
),
|
||||
// Always-visible character counter
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 4,
|
||||
vertical: 4,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
@@ -376,9 +401,11 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
||||
color: _characterCount > 155
|
||||
? Colors.red
|
||||
: (_characterCount > 140
|
||||
? Colors.orange
|
||||
: colorScheme.onSurfaceVariant),
|
||||
fontWeight: _characterCount > 140 ? FontWeight.bold : FontWeight.normal,
|
||||
? Colors.orange
|
||||
: colorScheme.onSurfaceVariant),
|
||||
fontWeight: _characterCount > 140
|
||||
? FontWeight.bold
|
||||
: FontWeight.normal,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -393,7 +420,10 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
||||
icon: const Icon(Icons.my_location, size: 18),
|
||||
label: Text(AppLocalizations.of(context)!.myLocation),
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
side: BorderSide(color: colorScheme.outline),
|
||||
),
|
||||
),
|
||||
@@ -404,12 +434,15 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
|
||||
? null
|
||||
: _sendDirectMessage,
|
||||
icon: const Icon(Icons.send),
|
||||
label: Text(AppLocalizations.of(context)!.sendDirectMessage),
|
||||
label: Text(
|
||||
AppLocalizations.of(context)!.sendDirectMessage,
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
backgroundColor: colorScheme.primary,
|
||||
foregroundColor: colorScheme.onPrimary,
|
||||
disabledBackgroundColor: colorScheme.surfaceContainerHighest,
|
||||
disabledBackgroundColor:
|
||||
colorScheme.surfaceContainerHighest,
|
||||
disabledForegroundColor: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user