From 518197eb4f213910b19d85c639cc111c29dc3568 Mon Sep 17 00:00:00 2001 From: Julian KOUNE Date: Thu, 5 Oct 2023 13:03:08 +0200 Subject: [PATCH] feat: add twake snackbar helper --- lib/pages/chat/add_widget_tile.dart | 5 +- lib/pages/chat/chat.dart | 17 ++----- lib/pages/chat/events/audio_player.dart | 13 ++---- lib/pages/chat/events/event_video_player.dart | 13 ++---- lib/pages/chat/events/message_content.dart | 17 +++---- lib/pages/chat_details/chat_details.dart | 15 ++---- lib/pages/chat_list/chat_list.dart | 15 ++---- lib/pages/chat_list/chat_list_item.dart | 7 +-- .../chat_permissions_settings.dart | 5 +- .../invitation_selection.dart | 7 +-- lib/pages/login/login.dart | 5 +- .../settings_profile/settings_profile.dart | 15 +----- .../settings_profile_item_style.dart | 18 -------- .../settings_security/settings_security.dart | 5 +- lib/pages/story/story_page.dart | 13 ++---- .../user_bottom_sheet/user_bottom_sheet.dart | 5 +- lib/utils/fluffy_share.dart | 5 +- lib/utils/twake_snackbar.dart | 46 +++++++++++++++++++ lib/utils/url_launcher.dart | 9 ++-- lib/utils/voip_plugin.dart | 10 ++-- lib/widgets/matrix.dart | 7 +-- 21 files changed, 100 insertions(+), 152 deletions(-) create mode 100644 lib/utils/twake_snackbar.dart diff --git a/lib/pages/chat/add_widget_tile.dart b/lib/pages/chat/add_widget_tile.dart index 89ad8976d1..366598fa23 100644 --- a/lib/pages/chat/add_widget_tile.dart +++ b/lib/pages/chat/add_widget_tile.dart @@ -1,3 +1,4 @@ +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; @@ -74,9 +75,7 @@ class AddWidgetTileState extends State { widget.room.addWidget(matrixWidget); Navigator.of(context).pop(); } catch (e) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(L10n.of(context)!.errorAddingWidget)), - ); + TwakeSnackBar.show(L10n.of(context)!.errorAddingWidget); } } diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 45a3cda06f..20ca1db98d 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -41,6 +41,7 @@ import 'package:fluffychat/utils/permission_dialog.dart'; import 'package:fluffychat/utils/permission_service.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/responsive/responsive_utils.dart'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/mixins/popup_context_menu_action_mixin.dart'; import 'package:fluffychat/widgets/mixins/popup_menu_widget_mixin.dart'; @@ -251,13 +252,7 @@ class ChatController extends State try { await timeline!.requestHistory(historyCount: _loadHistoryCount); } catch (err) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - (err).toLocalizedString(context), - ), - ), - ); + TwakeSnackBar.show((err).toLocalizedString(context)); rethrow; } } @@ -838,9 +833,7 @@ class ChatController extends State setState(() { selectedEvents.clear(); }); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(L10n.of(context)!.contentHasBeenReported)), - ); + TwakeSnackBar.show(L10n.of(context)!.contentHasBeenReported); } void redactEventsAction() async { @@ -1343,9 +1336,7 @@ class ChatController extends State try { await voipPlugin!.voip.inviteToCall(room!.id, callType); } catch (e) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(e.toLocalizedString(context))), - ); + TwakeSnackBar.show(e.toLocalizedString(context)); } } else { await showOkAlertDialog( diff --git a/lib/pages/chat/events/audio_player.dart b/lib/pages/chat/events/audio_player.dart index 7c2e559b26..a754cfab18 100644 --- a/lib/pages/chat/events/audio_player.dart +++ b/lib/pages/chat/events/audio_player.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:io'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -86,11 +87,7 @@ class AudioPlayerState extends State { _playAction(); } catch (e, s) { Logs().v('Could not download audio file', e, s); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(e.toLocalizedString(context)), - ), - ); + TwakeSnackBar.show(e.toLocalizedString(context)); } } @@ -136,11 +133,7 @@ class AudioPlayerState extends State { await audioPlayer.setAudioSource(MatrixFileAudioSource(matrixFile!)); } audioPlayer.play().catchError((e, s) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(L10n.of(context)!.oopsSomethingWentWrong), - ), - ); + TwakeSnackBar.show(L10n.of(context)!.oopsSomethingWentWrong); Logs().w('Error while playing audio', e, s); }); } diff --git a/lib/pages/chat/events/event_video_player.dart b/lib/pages/chat/events/event_video_player.dart index 1670d06fec..8ad5214ab4 100644 --- a/lib/pages/chat/events/event_video_player.dart +++ b/lib/pages/chat/events/event_video_player.dart @@ -4,6 +4,7 @@ import 'package:fluffychat/pages/chat/events/message_content_style.dart'; import 'package:fluffychat/pages/chat_details/chat_details_page_view/media/chat_details_media_style.dart'; import 'package:fluffychat/presentation/mixins/play_video_action_mixin.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:fluffychat/widgets/mxc_image.dart'; import 'package:flutter/material.dart'; @@ -66,18 +67,10 @@ class EventVideoPlayerState extends State _downloadStateNotifier.value = DownloadVideoState.done; } on MatrixConnectionException catch (e) { _downloadStateNotifier.value = DownloadVideoState.failed; - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(e.toLocalizedString(context)), - ), - ); + TwakeSnackBar.show(e.toLocalizedString(context)); } catch (e, s) { _downloadStateNotifier.value = DownloadVideoState.failed; - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(e.toLocalizedString(context)), - ), - ); + TwakeSnackBar.show(e.toLocalizedString(context)); Logs().w('Error while playing video', e, s); } } diff --git a/lib/pages/chat/events/message_content.dart b/lib/pages/chat/events/message_content.dart index 655de425c9..e13c0c8759 100644 --- a/lib/pages/chat/events/message_content.dart +++ b/lib/pages/chat/events/message_content.dart @@ -11,6 +11,7 @@ import 'package:fluffychat/presentation/model/file/display_image_info.dart'; import 'package:fluffychat/utils/extension/image_size_extension.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/string_extension.dart'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:fluffychat/utils/url_launcher.dart'; import 'package:fluffychat/widgets/twake_components/twake_preview_link/twake_link_preview.dart'; import 'package:flutter/material.dart'; @@ -61,16 +62,12 @@ class MessageContent extends StatelessWidget with PlayVideoActionMixin { void _verifyOrRequestKey(BuildContext context) async { final l10n = L10n.of(context)!; if (event.content['can_request_session'] != true) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - event.type == EventTypes.Encrypted - ? l10n.needPantalaimonWarning - : event.calcLocalizedBodyFallback( - MatrixLocals(l10n), - ), - ), - ), + TwakeSnackBar.show( + event.type == EventTypes.Encrypted + ? l10n.needPantalaimonWarning + : event.calcLocalizedBodyFallback( + MatrixLocals(l10n), + ), ); return; } diff --git a/lib/pages/chat_details/chat_details.dart b/lib/pages/chat_details/chat_details.dart index a161d16c19..03b197ce36 100644 --- a/lib/pages/chat_details/chat_details.dart +++ b/lib/pages/chat_details/chat_details.dart @@ -16,6 +16,7 @@ import 'package:fluffychat/presentation/mixins/play_video_action_mixin.dart'; import 'package:fluffychat/presentation/model/chat_details/chat_details_page_model.dart'; import 'package:fluffychat/utils/extension/build_context_extension.dart'; import 'package:fluffychat/utils/responsive/responsive_utils.dart'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:fluffychat/widgets/mxc_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -122,9 +123,7 @@ class ChatDetailsController extends State future: () => room.setName(input.single), ); if (success.error == null) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(L10n.of(context)!.displaynameHasBeenChanged)), - ); + TwakeSnackBar.show(L10n.of(context)!.displaynameHasBeenChanged); } } @@ -202,9 +201,7 @@ class ChatDetailsController extends State switch (option) { case AliasActions.copy: await Clipboard.setData(ClipboardData(text: select)); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(L10n.of(context)!.copiedToClipboard)), - ); + TwakeSnackBar.show(L10n.of(context)!.copiedToClipboard); break; case AliasActions.delete: await showFutureLoadingDialog( @@ -278,11 +275,7 @@ class ChatDetailsController extends State future: () => room.setDescription(input.single), ); if (success.error == null) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(L10n.of(context)!.groupDescriptionHasBeenChanged), - ), - ); + TwakeSnackBar.show(L10n.of(context)!.groupDescriptionHasBeenChanged); } } diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index 88efb224bd..593041181c 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -23,6 +23,7 @@ import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart'; import 'package:fluffychat/utils/responsive/responsive_utils.dart'; import 'package:fluffychat/utils/tor_stub.dart' if (dart.library.html) 'package:tor_detector_web/tor_detector_web.dart'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:fluffychat/widgets/mixins/popup_context_menu_action_mixin.dart'; import 'package:fluffychat/widgets/mixins/popup_menu_widget_mixin.dart'; import 'package:flutter/foundation.dart'; @@ -135,13 +136,7 @@ class ChatListController extends State ); } catch (e, s) { Logs().w('Searching has crashed', e, s); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - e.toLocalizedString(context), - ), - ), - ); + TwakeSnackBar.show(e.toLocalizedString(context)); } if (!isSearchMode) return; setState(() { @@ -420,11 +415,7 @@ class ChatListController extends State ); if (result.error == null) { if (!mounted) return; - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(L10n.of(context)!.chatHasBeenAddedToThisSpace), - ), - ); + TwakeSnackBar.show(L10n.of(context)!.chatHasBeenAddedToThisSpace); } conversationSelectionNotifier.value.clear(); diff --git a/lib/pages/chat_list/chat_list_item.dart b/lib/pages/chat_list/chat_list_item.dart index b4143af0f6..55af9c498b 100644 --- a/lib/pages/chat_list/chat_list_item.dart +++ b/lib/pages/chat_list/chat_list_item.dart @@ -5,6 +5,7 @@ import 'package:fluffychat/pages/chat_list/chat_list_item_style.dart'; import 'package:fluffychat/pages/chat_list/chat_list_item_subtitle.dart'; import 'package:fluffychat/pages/chat_list/chat_list_item_title.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:fluffychat/widgets/avatar/avatar.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; @@ -43,11 +44,7 @@ class ChatListItem extends StatelessWidget with ChatListItemMixin { if (activeChat) return; switch (room.membership) { case Membership.ban: - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(L10n.of(context)!.youHaveBeenBannedFromThisChat), - ), - ); + TwakeSnackBar.show(L10n.of(context)!.youHaveBeenBannedFromThisChat); return; case Membership.leave: context.go('/archive/${room.id}'); diff --git a/lib/pages/chat_permissions_settings/chat_permissions_settings.dart b/lib/pages/chat_permissions_settings/chat_permissions_settings.dart index 16875b5965..63df10faba 100644 --- a/lib/pages/chat_permissions_settings/chat_permissions_settings.dart +++ b/lib/pages/chat_permissions_settings/chat_permissions_settings.dart @@ -1,5 +1,6 @@ import 'dart:developer'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:flutter/material.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart'; @@ -29,9 +30,7 @@ class ChatPermissionsSettingsController extends State { }) async { final room = Matrix.of(context).client.getRoomById(roomId!)!; if (!room.canSendEvent(EventTypes.RoomPowerLevels)) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(L10n.of(context)!.noPermission)), - ); + TwakeSnackBar.show(L10n.of(context)!.noPermission); return; } final newLevel = await showPermissionChooser( diff --git a/lib/pages/invitation_selection/invitation_selection.dart b/lib/pages/invitation_selection/invitation_selection.dart index 9f4959ca95..fba6727dd6 100644 --- a/lib/pages/invitation_selection/invitation_selection.dart +++ b/lib/pages/invitation_selection/invitation_selection.dart @@ -1,5 +1,6 @@ import 'package:fluffychat/pages/new_group/contacts_selection.dart'; import 'package:fluffychat/pages/new_group/contacts_selection_view.dart'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:fluffychat/widgets/twake_app.dart'; import 'package:flutter/material.dart'; @@ -85,11 +86,7 @@ class InvitationSelectionController ), ); if (success.error == null) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(L10n.of(context)!.contactHasBeenInvitedToTheGroup), - ), - ); + TwakeSnackBar.show(L10n.of(context)!.contactHasBeenInvitedToTheGroup); onCloseDialogInvite(); inviteSuccessAction(); } diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index 429331e903..21aa7993a0 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:flutter/material.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart'; @@ -233,9 +234,7 @@ class LoginController extends State { ), ); if (success.error == null) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(L10n.of(context)!.passwordHasBeenChanged)), - ); + TwakeSnackBar.show(L10n.of(context)!.passwordHasBeenChanged); usernameController.text = input.single; passwordController.text = password.single; login(); diff --git a/lib/pages/settings_dashboard/settings_profile/settings_profile.dart b/lib/pages/settings_dashboard/settings_profile/settings_profile.dart index d05daeef85..ae6c9d92fa 100644 --- a/lib/pages/settings_dashboard/settings_profile/settings_profile.dart +++ b/lib/pages/settings_dashboard/settings_profile/settings_profile.dart @@ -11,7 +11,6 @@ import 'package:fluffychat/domain/usecase/room/upload_content_interactor.dart'; import 'package:fluffychat/domain/usecase/settings/update_profile_interactor.dart'; import 'package:fluffychat/event/twake_event_dispatcher.dart'; import 'package:fluffychat/event/twake_inapp_event_types.dart'; -import 'package:fluffychat/pages/settings_dashboard/settings_profile/settings_profile_item_style.dart'; import 'package:fluffychat/pages/settings_dashboard/settings_profile/settings_profile_state/get_avatar_ui_state.dart'; import 'package:fluffychat/pages/settings_dashboard/settings_profile/settings_profile_state/get_profile_ui_state.dart'; import 'package:fluffychat/pages/settings_dashboard/settings_profile/settings_profile_view.dart'; @@ -22,6 +21,7 @@ import 'package:fluffychat/presentation/mixins/single_image_picker_mixin.dart'; import 'package:fluffychat/utils/dialog/twake_loading_dialog.dart'; import 'package:fluffychat/utils/extension/value_notifier_extension.dart'; import 'package:fluffychat/utils/platform_infos.dart'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -463,18 +463,7 @@ class SettingsProfileController extends State switch (settingsProfileEnum) { case SettingsProfileEnum.matrixId: Clipboard.setData(ClipboardData(text: client.mxid(context))); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - width: SettingsProfileItemStyle.widthSnackBar(context), - padding: SettingsProfileItemStyle.snackBarPadding, - content: Text( - L10n.of(context)!.copiedMatrixIdToClipboard, - style: Theme.of(context).textTheme.bodyMedium?.copyWith( - color: Theme.of(context).colorScheme.background, - ), - ), - ), - ); + TwakeSnackBar.show(L10n.of(context)!.copiedMatrixIdToClipboard); break; default: break; diff --git a/lib/pages/settings_dashboard/settings_profile/settings_profile_item_style.dart b/lib/pages/settings_dashboard/settings_profile/settings_profile_item_style.dart index 1c27526b3f..dc359e972b 100644 --- a/lib/pages/settings_dashboard/settings_profile/settings_profile_item_style.dart +++ b/lib/pages/settings_dashboard/settings_profile/settings_profile_item_style.dart @@ -1,27 +1,9 @@ -import 'package:fluffychat/di/global/get_it_initializer.dart'; -import 'package:fluffychat/utils/responsive/responsive_utils.dart'; import 'package:flutter/material.dart'; class SettingsProfileItemStyle { - static ResponsiveUtils responsiveUtils = getIt.get(); - static const double iconSize = 24.0; static const double dividerSize = 2.0; static const EdgeInsetsDirectional itemBuilderPadding = EdgeInsetsDirectional.only(end: 8.0); - - static const EdgeInsetsDirectional snackBarPadding = - EdgeInsetsDirectional.symmetric( - horizontal: 16, - vertical: 14, - ); - - static double? widthSnackBar(BuildContext context) { - if (responsiveUtils.isWebDesktop(context)) { - return 334; - } else { - return null; - } - } } diff --git a/lib/pages/settings_dashboard/settings_security/settings_security.dart b/lib/pages/settings_dashboard/settings_security/settings_security.dart index 4652d7f1a4..20ddd568db 100644 --- a/lib/pages/settings_dashboard/settings_security/settings_security.dart +++ b/lib/pages/settings_dashboard/settings_security/settings_security.dart @@ -3,6 +3,7 @@ import 'dart:typed_data'; import 'package:fluffychat/pages/bootstrap/bootstrap_dialog.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:flutter/material.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart'; @@ -55,9 +56,7 @@ class SettingsSecurityController extends State { .changePassword(input.last, oldPassword: input.first), ); if (success.error == null) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(L10n.of(context)!.passwordHasBeenChanged)), - ); + TwakeSnackBar.show(L10n.of(context)!.passwordHasBeenChanged); } } diff --git a/lib/pages/story/story_page.dart b/lib/pages/story/story_page.dart index 691ac5b44d..afac023dfe 100644 --- a/lib/pages/story/story_page.dart +++ b/lib/pages/story/story_page.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:io'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:flutter/material.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart'; @@ -91,14 +92,10 @@ class StoryPageController extends State { await client.getRoomById(roomId)!.sendTextEvent(message); replyController.clear(); replyFocus.unfocus(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(L10n.of(context)!.replyHasBeenSent)), - ); + TwakeSnackBar.show(L10n.of(context)!.replyHasBeenSent); } catch (e, s) { Logs().w('Unable to reply to story', e, s); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(e.toLocalizedString(context))), - ); + TwakeSnackBar.show(e.toLocalizedString(context)); } finally { setState(() { replyLoading = false; @@ -352,9 +349,7 @@ class StoryPageController extends State { ); _modalOpened = false; if (result.error != null) return; - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(L10n.of(context)!.contentHasBeenReported)), - ); + TwakeSnackBar.show(L10n.of(context)!.contentHasBeenReported); } Future downloadAndDecryptAttachment( diff --git a/lib/pages/user_bottom_sheet/user_bottom_sheet.dart b/lib/pages/user_bottom_sheet/user_bottom_sheet.dart index 2fbe259956..d3553bd9ee 100644 --- a/lib/pages/user_bottom_sheet/user_bottom_sheet.dart +++ b/lib/pages/user_bottom_sheet/user_bottom_sheet.dart @@ -1,3 +1,4 @@ +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:flutter/material.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart'; @@ -91,9 +92,7 @@ class UserBottomSheetController extends State { ), ); if (result.error != null) return; - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(L10n.of(context)!.contentHasBeenReported)), - ); + TwakeSnackBar.show(L10n.of(context)!.contentHasBeenReported); break; case UserBottomSheetAction.mention: Navigator.of(context, rootNavigator: false).pop(); diff --git a/lib/utils/fluffy_share.dart b/lib/utils/fluffy_share.dart index b5f1321bc5..9cdf9fd8c2 100644 --- a/lib/utils/fluffy_share.dart +++ b/lib/utils/fluffy_share.dart @@ -1,3 +1,4 @@ +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -18,9 +19,7 @@ abstract class FluffyShare { await Clipboard.setData( ClipboardData(text: text), ); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(L10n.of(context)!.copiedToClipboard)), - ); + TwakeSnackBar.show(L10n.of(context)!.copiedToClipboard); return; } } diff --git a/lib/utils/twake_snackbar.dart b/lib/utils/twake_snackbar.dart new file mode 100644 index 0000000000..7111e8f9b4 --- /dev/null +++ b/lib/utils/twake_snackbar.dart @@ -0,0 +1,46 @@ +import 'package:fluffychat/di/global/get_it_initializer.dart'; +import 'package:fluffychat/utils/responsive/responsive_utils.dart'; +import 'package:fluffychat/widgets/twake_app.dart'; +import 'package:flutter/material.dart'; +import 'package:fluttertoast/fluttertoast.dart'; + +class TwakeSnackBarStyle { + static ResponsiveUtils responsiveUtils = getIt.get(); + + static const EdgeInsetsDirectional snackBarPadding = + EdgeInsetsDirectional.symmetric( + horizontal: 16, + vertical: 14, + ); + + static double? widthSnackBar(BuildContext context) { + if (responsiveUtils.isWebDesktop(context)) { + return 334; + } else { + return null; + } + } +} + +class TwakeSnackBar { + static void show(String message) { + final context = TwakeApp.routerKey.currentContext; + if (context == null) { + Fluttertoast.showToast(msg: message); + return; + } + + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + width: TwakeSnackBarStyle.widthSnackBar(context), + padding: TwakeSnackBarStyle.snackBarPadding, + content: Text( + message, + style: Theme.of(context).textTheme.bodyMedium?.copyWith( + color: Theme.of(context).colorScheme.background, + ), + ), + ), + ); + } +} diff --git a/lib/utils/url_launcher.dart b/lib/utils/url_launcher.dart index 5d11408a32..67d00f61b9 100644 --- a/lib/utils/url_launcher.dart +++ b/lib/utils/url_launcher.dart @@ -1,3 +1,4 @@ +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:flutter/material.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart'; @@ -34,9 +35,7 @@ class UrlLauncher { final uri = Uri.tryParse(url!); if (uri == null) { // we can't open this thing - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(L10n.of(context)!.cantOpenUri(url!))), - ); + TwakeSnackBar.show(L10n.of(context)!.cantOpenUri(url!)); return; } if (!{'https', 'http'}.contains(uri.scheme)) { @@ -74,9 +73,7 @@ class UrlLauncher { return; } if (uri.host.isEmpty) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(L10n.of(context)!.cantOpenUri(url!))), - ); + TwakeSnackBar.show(L10n.of(context)!.cantOpenUri(url!)); return; } // okay, we have either an http or an https URI. diff --git a/lib/utils/voip_plugin.dart b/lib/utils/voip_plugin.dart index a10414588a..a0db2ad799 100644 --- a/lib/utils/voip_plugin.dart +++ b/lib/utils/voip_plugin.dart @@ -1,5 +1,6 @@ import 'dart:core'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -165,13 +166,8 @@ class VoipPlugin with WidgetsBindingObserver implements WebRTCDelegate { addCallingOverlay(call.callId, call); try { if (!hasCallingAccount) { - ScaffoldMessenger.of(TwakeApp.routerKey.currentContext!) - .showSnackBar( - const SnackBar( - content: Text( - 'No calling accounts found (used for native calls UI)', - ), - ), + TwakeSnackBar.show( + 'No calling accounts found (used for native calls UI)', ); } } catch (e) { diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index 963c9cbb39..ceedbfd00a 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -17,6 +17,7 @@ import 'package:fluffychat/domain/repository/tom_configurations_repository.dart' import 'package:fluffychat/utils/client_manager.dart'; import 'package:fluffychat/utils/localized_exception_extension.dart'; import 'package:fluffychat/utils/platform_infos.dart'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:fluffychat/utils/uia_request_manager.dart'; import 'package:fluffychat/utils/url_launcher.dart'; import 'package:fluffychat/utils/voip_plugin.dart'; @@ -346,11 +347,7 @@ class MatrixState extends State with WidgetsBindingObserver { _cancelSubs(c.clientName); widget.clients.remove(c); ClientManager.removeClientNameFromStore(c.clientName); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(L10n.of(context)!.oneClientLoggedOut), - ), - ); + TwakeSnackBar.show(L10n.of(context)!.oneClientLoggedOut); if (state != LoginState.loggedIn) { TwakeApp.router.go('/rooms');