refactor: Remove unnecessary toast notifications and improve code formatting

This commit is contained in:
Janez T
2025-10-23 19:36:24 +02:00
parent 200e506df8
commit d64c78542b
4 changed files with 76 additions and 115 deletions

View File

@@ -195,16 +195,6 @@ class _HomeScreenState extends State<HomeScreen>
// Send flood advertisement // Send flood advertisement
await connectionProvider.sendSelfAdvert(floodMode: true); await connectionProvider.sendSelfAdvert(floodMode: true);
if (context.mounted) {
ToastLogger.success(
context,
AppLocalizations.of(context)!.advertisedAtLocation(
position.latitude.toStringAsFixed(6),
position.longitude.toStringAsFixed(6),
),
);
}
} catch (e) { } catch (e) {
debugPrint('❌ Failed to advertise device: $e'); debugPrint('❌ Failed to advertise device: $e');
if (context.mounted) { if (context.mounted) {

View File

@@ -220,7 +220,6 @@ class _MessagesTabState extends State<MessagesTab> {
// Show confirmation toast // Show confirmation toast
if (!mounted) return; if (!mounted) return;
ToastLogger.success(context, 'Messages will be sent to: $recipientName');
} }
/// Get icon for current destination type /// Get icon for current destination type
@@ -389,16 +388,24 @@ class _MessagesTabState extends State<MessagesTab> {
isScrollControlled: true, isScrollControlled: true,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
builder: (context) => SarUpdateSheet( builder: (context) => SarUpdateSheet(
onSend: (emoji, name, position, roomPublicKey, sendToChannel, colorIndex) async { onSend:
await _sendSarMessage( (
emoji, emoji,
name, name,
position, position,
roomPublicKey, roomPublicKey,
sendToChannel, sendToChannel,
colorIndex, colorIndex,
); ) async {
}, await _sendSarMessage(
emoji,
name,
position,
roomPublicKey,
sendToChannel,
colorIndex,
);
},
), ),
); );
} }
@@ -468,7 +475,6 @@ class _MessagesTabState extends State<MessagesTab> {
); );
if (!mounted) return; if (!mounted) return;
ToastLogger.success(context, 'SAR marker broadcast to public channel');
} else { } else {
// Create message ID // Create message ID
final messageId = '${DateTime.now().millisecondsSinceEpoch}_sent'; final messageId = '${DateTime.now().millisecondsSinceEpoch}_sent';
@@ -540,13 +546,7 @@ class _MessagesTabState extends State<MessagesTab> {
debugPrint( debugPrint(
'🔄 [MessagesTab] Manual refresh triggered - syncing messages', '🔄 [MessagesTab] Manual refresh triggered - syncing messages',
); );
final messageCount = await connectionProvider.syncAllMessages();
if (!mounted) return; if (!mounted) return;
if (messageCount > 0) {
ToastLogger.success(context, 'Synced $messageCount message(s)');
} else {
ToastLogger.info(context, 'No new messages');
}
} catch (e) { } catch (e) {
debugPrint('❌ [MessagesTab] Sync error: $e'); debugPrint('❌ [MessagesTab] Sync error: $e');
if (!mounted) return; if (!mounted) return;
@@ -566,7 +566,8 @@ class _MessagesTabState extends State<MessagesTab> {
} }
// If a contact or room is selected, filter by recipient // If a contact or room is selected, filter by recipient
if ((_destinationType == MessageDestinationPreferences.destinationTypeContact || if ((_destinationType ==
MessageDestinationPreferences.destinationTypeContact ||
_destinationType == _destinationType ==
MessageDestinationPreferences.destinationTypeRoom) && MessageDestinationPreferences.destinationTypeRoom) &&
_selectedRecipient != null) { _selectedRecipient != null) {
@@ -882,8 +883,6 @@ class _MessageBubble extends StatelessWidget {
if (!sentSuccessfully) { if (!sentSuccessfully) {
messagesProvider.markMessageFailed(retryMessageId); messagesProvider.markMessageFailed(retryMessageId);
ToastLogger.error(context, 'Failed to resend message'); ToastLogger.error(context, 'Failed to resend message');
} else {
ToastLogger.info(context, 'Retrying message...');
} }
} else if (failedMessage.messageType == MessageType.channel) { } else if (failedMessage.messageType == MessageType.channel) {
// Channel message retry // Channel message retry
@@ -894,8 +893,6 @@ class _MessageBubble extends StatelessWidget {
); );
if (!context.mounted) return; if (!context.mounted) return;
ToastLogger.info(context, 'Retrying message...');
} }
} catch (e) { } catch (e) {
if (!context.mounted) return; if (!context.mounted) return;
@@ -1033,7 +1030,6 @@ class _MessageBubble extends StatelessWidget {
final messagesProvider = context.read<MessagesProvider>(); final messagesProvider = context.read<MessagesProvider>();
messagesProvider.deleteMessage(message.id); messagesProvider.deleteMessage(message.id);
Navigator.pop(context); Navigator.pop(context);
ToastLogger.info(context, l10n.messageDeleted);
}, },
style: TextButton.styleFrom(foregroundColor: Colors.red), style: TextButton.styleFrom(foregroundColor: Colors.red),
child: Text(l10n.delete), child: Text(l10n.delete),
@@ -1080,13 +1076,8 @@ class _MessageBubble extends StatelessWidget {
// Share the location // Share the location
SharePlus.instance.share( SharePlus.instance.share(
ShareParams( ShareParams(text: shareText, subject: l10n.sarLocationShare),
text: shareText,
subject: l10n.sarLocationShare,
),
); );
ToastLogger.success(context, l10n.locationShared);
} }
@override @override

View File

@@ -409,18 +409,6 @@ class ContactTile extends StatelessWidget {
// Determine if we should use flooding (no path) or direct (has path) // Determine if we should use flooding (no path) or direct (has path)
final hasPath = contact.hasPath; 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 // Use smart ping with automatic fallback
final result = await connectionProvider.smartPing( final result = await connectionProvider.smartPing(
contactPublicKey: contact.publicKey, contactPublicKey: contact.publicKey,
@@ -440,17 +428,7 @@ class ContactTile extends StatelessWidget {
// Show final result // Show final result
if (context.mounted) { if (context.mounted) {
if (result.success) { if (!result.success) {
ToastLogger.success(
context,
AppLocalizations.of(context)!.pingSuccessful(
contact.displayName,
result.retriedWithFlooding
? AppLocalizations.of(context)!.viaFloodingFallback
: '',
),
);
} else {
ToastLogger.error( ToastLogger.error(
context, context,
AppLocalizations.of(context)!.pingFailed(contact.displayName), AppLocalizations.of(context)!.pingFailed(contact.displayName),
@@ -494,12 +472,6 @@ class ContactTile extends StatelessWidget {
// Switch to map tab using callback // Switch to map tab using callback
onNavigateToMap?.call(); 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>(); final contactsProvider = context.read<ContactsProvider>();
try { try {
// Show loading toast
ToastLogger.info(
context,
AppLocalizations.of(context)!.removingContact(contact.displayName),
);
// Remove contact from provider (which will also remove from device) // Remove contact from provider (which will also remove from device)
await contactsProvider.removeContact( await contactsProvider.removeContact(
contact.publicKeyHex, contact.publicKeyHex,
@@ -552,13 +518,6 @@ class ContactTile extends StatelessWidget {
} }
}, },
); );
if (context.mounted) {
ToastLogger.success(
context,
AppLocalizations.of(context)!.contactRemoved(contact.displayName),
);
}
} catch (e) { } catch (e) {
if (context.mounted) { if (context.mounted) {
ToastLogger.error( ToastLogger.error(
@@ -830,12 +789,6 @@ class ContactTile extends StatelessWidget {
contact.publicKey, contact.publicKey,
zeroHop: true, zeroHop: true,
); );
ToastLogger.info(
context,
AppLocalizations.of(
context,
)!.requestingTelemetry(contact.displayName),
);
}, },
icon: const Icon(Icons.refresh, size: 18), icon: const Icon(Icons.refresh, size: 18),
label: Text(AppLocalizations.of(context)!.refresh), label: Text(AppLocalizations.of(context)!.refresh),
@@ -912,12 +865,6 @@ class ContactTile extends StatelessWidget {
child: OutlinedButton.icon( child: OutlinedButton.icon(
onPressed: () { onPressed: () {
connectionProvider.resetPath(contact.publicKey); connectionProvider.resetPath(contact.publicKey);
ToastLogger.info(
context,
AppLocalizations.of(
context,
)!.pathResetInfo(contact.displayName),
);
}, },
icon: const Icon(Icons.route), icon: const Icon(Icons.route),
label: Text(AppLocalizations.of(context)!.resetPath), label: Text(AppLocalizations.of(context)!.resetPath),

View File

@@ -73,13 +73,17 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
); );
// Format location text // 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 // Check if adding location would exceed limit
final currentText = _textController.text; final currentText = _textController.text;
if (currentText.length + locationText.length > _maxCharacters) { if (currentText.length + locationText.length > _maxCharacters) {
if (!mounted) return; if (!mounted) return;
ToastLogger.error(context, 'Adding location would exceed 160 character limit'); ToastLogger.error(
context,
'Adding location would exceed 160 character limit',
);
return; return;
} }
@@ -94,13 +98,14 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
_textController.text = newText; _textController.text = newText;
// Move cursor to end of inserted text // 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( _textController.selection = TextSelection.fromPosition(
TextPosition(offset: newCursorPosition), TextPosition(offset: newCursorPosition),
); );
if (!mounted) return; if (!mounted) return;
ToastLogger.success(context, 'Location inserted');
} catch (e) { } catch (e) {
if (!mounted) return; if (!mounted) return;
ToastLogger.error(context, 'Failed to get location: $e'); ToastLogger.error(context, 'Failed to get location: $e');
@@ -116,7 +121,10 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
if (!connectionProvider.deviceInfo.isConnected) { if (!connectionProvider.deviceInfo.isConnected) {
if (!mounted) return; if (!mounted) return;
ToastLogger.error(context, AppLocalizations.of(context)!.notConnectedToDevice); ToastLogger.error(
context,
AppLocalizations.of(context)!.notConnectedToDevice,
);
return; return;
} }
@@ -140,7 +148,8 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
text: text, text: text,
receivedAt: DateTime.now(), receivedAt: DateTime.now(),
deliveryStatus: MessageDeliveryStatus.sending, 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 // Add to messages list with "sending" status
@@ -174,11 +183,12 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
if (!mounted) return; if (!mounted) return;
Navigator.pop(context); // Close the dialog Navigator.pop(context); // Close the dialog
ToastLogger.success(context, AppLocalizations.of(context)!.directMessageSentTo(widget.contact.displayName));
} catch (e) { } catch (e) {
if (!mounted) return; 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), padding: const EdgeInsets.all(16),
decoration: BoxDecoration( decoration: BoxDecoration(
color: colorScheme.surfaceContainerHighest, color: colorScheme.surfaceContainerHighest,
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)), borderRadius: const BorderRadius.vertical(
top: Radius.circular(20),
),
), ),
child: Row( child: Row(
children: [ children: [
@@ -265,12 +277,15 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
), ),
initialZoom: 13.0, initialZoom: 13.0,
interactionOptions: const InteractionOptions( interactionOptions: const InteractionOptions(
flags: InteractiveFlag.pinchZoom | InteractiveFlag.drag, flags:
InteractiveFlag.pinchZoom |
InteractiveFlag.drag,
), ),
), ),
children: [ children: [
TileLayer( TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', urlTemplate:
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.meshcore.sar', userAgentPackageName: 'com.meshcore.sar',
), ),
MarkerLayer( MarkerLayer(
@@ -301,7 +316,11 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon(Icons.gps_fixed, size: 14, color: colorScheme.onSurfaceVariant), Icon(
Icons.gps_fixed,
size: 14,
color: colorScheme.onSurfaceVariant,
),
const SizedBox(width: 4), const SizedBox(width: 4),
Text( Text(
'${contactLocation.latitude.toStringAsFixed(5)}, ${contactLocation.longitude.toStringAsFixed(5)}', '${contactLocation.latitude.toStringAsFixed(5)}, ${contactLocation.longitude.toStringAsFixed(5)}',
@@ -355,7 +374,10 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
), ),
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: colorScheme.primary, width: 2), borderSide: BorderSide(
color: colorScheme.primary,
width: 2,
),
), ),
contentPadding: const EdgeInsets.all(16), contentPadding: const EdgeInsets.all(16),
counterText: '', // Hide default counter counterText: '', // Hide default counter
@@ -365,7 +387,10 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
), ),
// Always-visible character counter // Always-visible character counter
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4), padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 4,
),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
children: [ children: [
@@ -376,9 +401,11 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
color: _characterCount > 155 color: _characterCount > 155
? Colors.red ? Colors.red
: (_characterCount > 140 : (_characterCount > 140
? Colors.orange ? Colors.orange
: colorScheme.onSurfaceVariant), : colorScheme.onSurfaceVariant),
fontWeight: _characterCount > 140 ? FontWeight.bold : FontWeight.normal, fontWeight: _characterCount > 140
? FontWeight.bold
: FontWeight.normal,
), ),
), ),
], ],
@@ -393,7 +420,10 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
icon: const Icon(Icons.my_location, size: 18), icon: const Icon(Icons.my_location, size: 18),
label: Text(AppLocalizations.of(context)!.myLocation), label: Text(AppLocalizations.of(context)!.myLocation),
style: OutlinedButton.styleFrom( style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
side: BorderSide(color: colorScheme.outline), side: BorderSide(color: colorScheme.outline),
), ),
), ),
@@ -404,12 +434,15 @@ class _DirectMessageSheetState extends State<DirectMessageSheet> {
? null ? null
: _sendDirectMessage, : _sendDirectMessage,
icon: const Icon(Icons.send), icon: const Icon(Icons.send),
label: Text(AppLocalizations.of(context)!.sendDirectMessage), label: Text(
AppLocalizations.of(context)!.sendDirectMessage,
),
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 14), padding: const EdgeInsets.symmetric(vertical: 14),
backgroundColor: colorScheme.primary, backgroundColor: colorScheme.primary,
foregroundColor: colorScheme.onPrimary, foregroundColor: colorScheme.onPrimary,
disabledBackgroundColor: colorScheme.surfaceContainerHighest, disabledBackgroundColor:
colorScheme.surfaceContainerHighest,
disabledForegroundColor: colorScheme.onSurfaceVariant, disabledForegroundColor: colorScheme.onSurfaceVariant,
), ),
), ),