From d64c78542bfff84e5caffd2211a81858686b5a0e Mon Sep 17 00:00:00 2001 From: Janez T Date: Thu, 23 Oct 2025 19:36:24 +0200 Subject: [PATCH] refactor: Remove unnecessary toast notifications and improve code formatting --- lib/screens/home_screen.dart | 10 --- lib/screens/messages_tab.dart | 51 ++++++------- lib/widgets/contacts/contact_tile.dart | 55 +------------- .../contacts/direct_message_sheet.dart | 75 +++++++++++++------ 4 files changed, 76 insertions(+), 115 deletions(-) diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index cbe6657..e1fd010 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -195,16 +195,6 @@ class _HomeScreenState extends State // Send flood advertisement 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) { debugPrint('❌ Failed to advertise device: $e'); if (context.mounted) { diff --git a/lib/screens/messages_tab.dart b/lib/screens/messages_tab.dart index b98ef54..76eb9da 100644 --- a/lib/screens/messages_tab.dart +++ b/lib/screens/messages_tab.dart @@ -220,7 +220,6 @@ class _MessagesTabState extends State { // Show confirmation toast if (!mounted) return; - ToastLogger.success(context, 'Messages will be sent to: $recipientName'); } /// Get icon for current destination type @@ -389,16 +388,24 @@ class _MessagesTabState extends State { isScrollControlled: true, backgroundColor: Colors.transparent, builder: (context) => SarUpdateSheet( - onSend: (emoji, name, position, roomPublicKey, sendToChannel, colorIndex) async { - await _sendSarMessage( - emoji, - name, - position, - roomPublicKey, - sendToChannel, - colorIndex, - ); - }, + onSend: + ( + emoji, + name, + position, + roomPublicKey, + sendToChannel, + colorIndex, + ) async { + await _sendSarMessage( + emoji, + name, + position, + roomPublicKey, + sendToChannel, + colorIndex, + ); + }, ), ); } @@ -468,7 +475,6 @@ class _MessagesTabState extends State { ); if (!mounted) return; - ToastLogger.success(context, 'SAR marker broadcast to public channel'); } else { // Create message ID final messageId = '${DateTime.now().millisecondsSinceEpoch}_sent'; @@ -540,13 +546,7 @@ class _MessagesTabState extends State { debugPrint( '🔄 [MessagesTab] Manual refresh triggered - syncing messages', ); - final messageCount = await connectionProvider.syncAllMessages(); if (!mounted) return; - if (messageCount > 0) { - ToastLogger.success(context, 'Synced $messageCount message(s)'); - } else { - ToastLogger.info(context, 'No new messages'); - } } catch (e) { debugPrint('❌ [MessagesTab] Sync error: $e'); if (!mounted) return; @@ -566,7 +566,8 @@ class _MessagesTabState extends State { } // If a contact or room is selected, filter by recipient - if ((_destinationType == MessageDestinationPreferences.destinationTypeContact || + if ((_destinationType == + MessageDestinationPreferences.destinationTypeContact || _destinationType == MessageDestinationPreferences.destinationTypeRoom) && _selectedRecipient != null) { @@ -882,8 +883,6 @@ class _MessageBubble extends StatelessWidget { if (!sentSuccessfully) { messagesProvider.markMessageFailed(retryMessageId); ToastLogger.error(context, 'Failed to resend message'); - } else { - ToastLogger.info(context, 'Retrying message...'); } } else if (failedMessage.messageType == MessageType.channel) { // Channel message retry @@ -894,8 +893,6 @@ class _MessageBubble extends StatelessWidget { ); if (!context.mounted) return; - - ToastLogger.info(context, 'Retrying message...'); } } catch (e) { if (!context.mounted) return; @@ -1033,7 +1030,6 @@ class _MessageBubble extends StatelessWidget { final messagesProvider = context.read(); messagesProvider.deleteMessage(message.id); Navigator.pop(context); - ToastLogger.info(context, l10n.messageDeleted); }, style: TextButton.styleFrom(foregroundColor: Colors.red), child: Text(l10n.delete), @@ -1080,13 +1076,8 @@ class _MessageBubble extends StatelessWidget { // Share the location SharePlus.instance.share( - ShareParams( - text: shareText, - subject: l10n.sarLocationShare, - ), + ShareParams(text: shareText, subject: l10n.sarLocationShare), ); - - ToastLogger.success(context, l10n.locationShared); } @override diff --git a/lib/widgets/contacts/contact_tile.dart b/lib/widgets/contacts/contact_tile.dart index cac389a..0bffc8d 100644 --- a/lib/widgets/contacts/contact_tile.dart +++ b/lib/widgets/contacts/contact_tile.dart @@ -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(); 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), diff --git a/lib/widgets/contacts/direct_message_sheet.dart b/lib/widgets/contacts/direct_message_sheet.dart index 1fe904d..cddcc9f 100644 --- a/lib/widgets/contacts/direct_message_sheet.dart +++ b/lib/widgets/contacts/direct_message_sheet.dart @@ -73,13 +73,17 @@ class _DirectMessageSheetState extends State { ); // 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 { _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 { 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 { 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 { 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 { 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 { ), 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 { 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 { ), 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 { ), // 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 { 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 { 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 { ? 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, ), ),