Skip to content

Commit

Permalink
feat: add twake snackbar helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian KOUNE committed Oct 5, 2023
1 parent 510b2e0 commit 97ee9da
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 142 deletions.
5 changes: 2 additions & 3 deletions lib/pages/chat/add_widget_tile.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:fluffychat/utils/twake_snackbar.dart';
import 'package:flutter/material.dart';

import 'package:flutter_gen/gen_l10n/l10n.dart';
Expand Down Expand Up @@ -74,9 +75,7 @@ class AddWidgetTileState extends State<AddWidgetTile> {
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);
}
}

Expand Down
17 changes: 4 additions & 13 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -251,13 +252,7 @@ class ChatController extends State<Chat>
try {
await timeline!.requestHistory(historyCount: _loadHistoryCount);
} catch (err) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
(err).toLocalizedString(context),
),
),
);
TwakeSnackBar.show((err).toLocalizedString(context));
rethrow;
}
}
Expand Down Expand Up @@ -838,9 +833,7 @@ class ChatController extends State<Chat>
setState(() {
selectedEvents.clear();
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(L10n.of(context)!.contentHasBeenReported)),
);
TwakeSnackBar.show(L10n.of(context)!.contentHasBeenReported);
}

void redactEventsAction() async {
Expand Down Expand Up @@ -1343,9 +1336,7 @@ class ChatController extends State<Chat>
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(
Expand Down
13 changes: 3 additions & 10 deletions lib/pages/chat/events/audio_player.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -86,11 +87,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
_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));
}
}

Expand Down Expand Up @@ -136,11 +133,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
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);
});
}
Expand Down
13 changes: 3 additions & 10 deletions lib/pages/chat/events/event_video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -66,18 +67,10 @@ class EventVideoPlayerState extends State<EventVideoPlayer>
_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);
}
}
Expand Down
15 changes: 4 additions & 11 deletions lib/pages/chat_details/chat_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -122,9 +123,7 @@ class ChatDetailsController extends State<ChatDetails>
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);
}
}

Expand Down Expand Up @@ -202,9 +201,7 @@ class ChatDetailsController extends State<ChatDetails>
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(
Expand Down Expand Up @@ -278,11 +275,7 @@ class ChatDetailsController extends State<ChatDetails>
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);
}
}

Expand Down
15 changes: 3 additions & 12 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -135,13 +136,7 @@ class ChatListController extends State<ChatList>
);
} 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(() {
Expand Down Expand Up @@ -420,11 +415,7 @@ class ChatListController extends State<ChatList>
);
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();
Expand Down
7 changes: 2 additions & 5 deletions lib/pages/chat_list/chat_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}');
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -29,9 +30,7 @@ class ChatPermissionsSettingsController extends State<ChatPermissionsSettings> {
}) 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(
Expand Down
7 changes: 2 additions & 5 deletions lib/pages/invitation_selection/invitation_selection.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 2 additions & 3 deletions lib/pages/login/login.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -233,9 +234,7 @@ class LoginController extends State<Login> {
),
);
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -463,18 +463,7 @@ class SettingsProfileController extends State<SettingsProfile>
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ResponsiveUtils>();

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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -55,9 +56,7 @@ class SettingsSecurityController extends State<SettingsSecurity> {
.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);
}
}

Expand Down
13 changes: 4 additions & 9 deletions lib/pages/story/story_page.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -91,14 +92,10 @@ class StoryPageController extends State<StoryPage> {
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;
Expand Down Expand Up @@ -352,9 +349,7 @@ class StoryPageController extends State<StoryPage> {
);
_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<MatrixFile> downloadAndDecryptAttachment(
Expand Down
Loading

0 comments on commit 97ee9da

Please sign in to comment.