From 7f6c914fca5488824884eb0143520c3b506e38fe Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sat, 10 Sep 2022 12:11:11 +0200 Subject: [PATCH] fix: Popup menu without elevation --- lib/pages/chat/chat_input_row.dart | 5 +- lib/pages/chat/chat_view.dart | 3 +- lib/pages/chat_details/chat_details_view.dart | 7 +-- .../chat_encryption_settings_view.dart | 5 +- .../chat_list/client_chooser_button.dart | 31 ++++++------- lib/pages/story/story_view.dart | 3 +- .../user_bottom_sheet_view.dart | 3 +- lib/widgets/chat_settings_popup_menu.dart | 3 +- lib/widgets/log_view.dart | 4 +- lib/widgets/m2_popup_menu_button.dart | 46 +++++++++++++++++++ 10 files changed, 80 insertions(+), 30 deletions(-) create mode 100644 lib/widgets/m2_popup_menu_button.dart diff --git a/lib/pages/chat/chat_input_row.dart b/lib/pages/chat/chat_input_row.dart index 2152bad6..da4e63cc 100644 --- a/lib/pages/chat/chat_input_row.dart +++ b/lib/pages/chat/chat_input_row.dart @@ -10,6 +10,7 @@ import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/matrix.dart'; +import '../../widgets/m2_popup_menu_button.dart'; import 'chat.dart'; import 'input_bar.dart'; @@ -89,7 +90,7 @@ class ChatInputRow extends StatelessWidget { alignment: Alignment.center, clipBehavior: Clip.hardEdge, decoration: const BoxDecoration(), - child: PopupMenuButton( + child: M2PopupMenuButton( icon: const Icon(Icons.add_outlined), onSelected: controller.onAddPopupMenuButtonSelected, itemBuilder: (BuildContext context) => @@ -295,7 +296,7 @@ class _ChatAccountPicker extends StatelessWidget { padding: const EdgeInsets.all(8.0), child: FutureBuilder( future: controller.sendingClient!.fetchOwnProfile(), - builder: (context, snapshot) => PopupMenuButton( + builder: (context, snapshot) => M2PopupMenuButton( onSelected: _popupMenuButtonSelected, itemBuilder: (BuildContext context) => clients .map((client) => PopupMenuItem( diff --git a/lib/pages/chat/chat_view.dart b/lib/pages/chat/chat_view.dart index 7e873560..907de5c4 100644 --- a/lib/pages/chat/chat_view.dart +++ b/lib/pages/chat/chat_view.dart @@ -21,6 +21,7 @@ import 'package:fluffychat/widgets/connection_status_header.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/unread_badge_back_button.dart'; import '../../utils/stream_extension.dart'; +import '../../widgets/m2_popup_menu_button.dart'; import 'chat_emoji_picker.dart'; import 'chat_input_row.dart'; @@ -65,7 +66,7 @@ class ChatView extends StatelessWidget { tooltip: L10n.of(context)!.pinMessage, ), if (controller.selectedEvents.length == 1) - PopupMenuButton<_EventContextAction>( + M2PopupMenuButton<_EventContextAction>( onSelected: (action) { switch (action) { case _EventContextAction.info: diff --git a/lib/pages/chat_details/chat_details_view.dart b/lib/pages/chat_details/chat_details_view.dart index 7fd4b4d6..f3d4aafe 100644 --- a/lib/pages/chat_details/chat_details_view.dart +++ b/lib/pages/chat_details/chat_details_view.dart @@ -16,6 +16,7 @@ import 'package:fluffychat/widgets/content_banner.dart'; import 'package:fluffychat/widgets/layouts/max_width_body.dart'; import 'package:fluffychat/widgets/matrix.dart'; import '../../utils/url_launcher.dart'; +import '../../widgets/m2_popup_menu_button.dart'; class ChatDetailsView extends StatelessWidget { final ChatDetailsController controller; @@ -197,7 +198,7 @@ class ChatDetailsView extends StatelessWidget { Text(L10n.of(context)!.setCustomEmotes), onTap: controller.goToEmoteSettings, ), - PopupMenuButton( + M2PopupMenuButton( onSelected: controller.setJoinRulesAction, itemBuilder: (BuildContext context) => >[ @@ -231,7 +232,7 @@ class ChatDetailsView extends StatelessWidget { ), ), ), - PopupMenuButton( + M2PopupMenuButton( onSelected: controller.setHistoryVisibilityAction, itemBuilder: (BuildContext context) => @@ -284,7 +285,7 @@ class ChatDetailsView extends StatelessWidget { ), ), if (room.joinRules == JoinRules.public) - PopupMenuButton( + M2PopupMenuButton( onSelected: controller.setGuestAccessAction, itemBuilder: (BuildContext context) => >[ diff --git a/lib/pages/chat_encryption_settings/chat_encryption_settings_view.dart b/lib/pages/chat_encryption_settings/chat_encryption_settings_view.dart index 585ec777..71cd6abb 100644 --- a/lib/pages/chat_encryption_settings/chat_encryption_settings_view.dart +++ b/lib/pages/chat_encryption_settings/chat_encryption_settings_view.dart @@ -9,6 +9,7 @@ import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/layouts/max_width_body.dart'; import 'package:fluffychat/widgets/matrix.dart'; import '../../utils/matrix_sdk_extensions.dart/device_extension.dart'; +import '../../widgets/m2_popup_menu_button.dart'; class ChatEncryptionSettingsView extends StatelessWidget { final ChatEncryptionSettingsController controller; @@ -73,7 +74,7 @@ class ChatEncryptionSettingsView extends StatelessWidget { deviceKeys[i].userId != deviceKeys[i - 1].userId) ...{ const Divider(height: 1, thickness: 1), - PopupMenuButton( + M2PopupMenuButton( onSelected: (dynamic action) => controller .onSelected(context, action, deviceKeys[i]), itemBuilder: (c) { @@ -115,7 +116,7 @@ class ChatEncryptionSettingsView extends StatelessWidget { ), ), }, - PopupMenuButton( + M2PopupMenuButton( onSelected: (dynamic action) => controller .onSelected(context, action, deviceKeys[i]), itemBuilder: (c) { diff --git a/lib/pages/chat_list/client_chooser_button.dart b/lib/pages/chat_list/client_chooser_button.dart index 66048955..09303118 100644 --- a/lib/pages/chat_list/client_chooser_button.dart +++ b/lib/pages/chat_list/client_chooser_button.dart @@ -9,6 +9,7 @@ import 'package:vrouter/vrouter.dart'; import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/matrix.dart'; import '../../utils/fluffy_share.dart'; +import '../../widgets/m2_popup_menu_button.dart'; import 'chat_list.dart'; class ClientChooserButton extends StatelessWidget { @@ -191,24 +192,18 @@ class ClientChooserButton extends StatelessWidget { onKeysPressed: () => _previousAccount(matrix, context), child: Container(), ), - Theme( - data: Theme.of(context), - child: PopupMenuButton( - shape: Border.all( - color: Theme.of(context).dividerColor, - ), - onSelected: (o) => _clientSelected(o, context), - itemBuilder: _bundleMenuItems, - child: Material( - color: Colors.transparent, - borderRadius: BorderRadius.circular(99), - child: Avatar( - mxContent: snapshot.data?.avatarUrl, - name: snapshot.data?.displayName ?? - matrix.client.userID!.localpart, - size: 28, - fontSize: 12, - ), + M2PopupMenuButton( + onSelected: (o) => _clientSelected(o, context), + itemBuilder: _bundleMenuItems, + child: Material( + color: Colors.transparent, + borderRadius: BorderRadius.circular(99), + child: Avatar( + mxContent: snapshot.data?.avatarUrl, + name: snapshot.data?.displayName ?? + matrix.client.userID!.localpart, + size: 28, + fontSize: 12, ), ), ), diff --git a/lib/pages/story/story_view.dart b/lib/pages/story/story_view.dart index d6590bf5..c5216b54 100644 --- a/lib/pages/story/story_view.dart +++ b/lib/pages/story/story_view.dart @@ -14,6 +14,7 @@ import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/string_color.dart'; import 'package:fluffychat/utils/url_launcher.dart'; import 'package:fluffychat/widgets/avatar.dart'; +import '../../widgets/m2_popup_menu_button.dart'; class StoryView extends StatelessWidget { final StoryPageController controller; @@ -101,7 +102,7 @@ class StoryView extends StatelessWidget { icon: Icon(Icons.adaptive.share_outlined), onPressed: controller.share, ), - PopupMenuButton( + M2PopupMenuButton( color: Colors.white, onSelected: controller.onPopupStoryAction, itemBuilder: (context) => [ diff --git a/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart b/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart index da9933e0..bac02425 100644 --- a/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart +++ b/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart @@ -9,6 +9,7 @@ import 'package:fluffychat/config/themes.dart'; import 'package:fluffychat/utils/fluffy_share.dart'; import '../../utils/matrix_sdk_extensions.dart/presence_extension.dart'; import '../../widgets/content_banner.dart'; +import '../../widgets/m2_popup_menu_button.dart'; import '../../widgets/matrix.dart'; import 'user_bottom_sheet.dart'; @@ -43,7 +44,7 @@ class UserBottomSheetView extends StatelessWidget { title: Text(user.calcDisplayname()), actions: [ if (user.id != client.userID) - PopupMenuButton( + M2PopupMenuButton( itemBuilder: (_) => [ if (controller.widget.onMention != null) PopupMenuItem( diff --git a/lib/widgets/chat_settings_popup_menu.dart b/lib/widgets/chat_settings_popup_menu.dart index c3cd26e6..a38bcc9b 100644 --- a/lib/widgets/chat_settings_popup_menu.dart +++ b/lib/widgets/chat_settings_popup_menu.dart @@ -14,6 +14,7 @@ import 'package:vrouter/vrouter.dart'; import 'package:fluffychat/pages/chat/cupertino_widgets_bottom_sheet.dart'; import 'package:fluffychat/pages/chat/edit_widgets_dialog.dart'; import 'package:fluffychat/pages/chat/widgets_bottom_sheet.dart'; +import 'm2_popup_menu_button.dart'; import 'matrix.dart'; class ChatSettingsPopupMenu extends StatefulWidget { @@ -125,7 +126,7 @@ class ChatSettingsPopupMenuState extends State { onKeysPressed: _showWidgets, child: Container(), ), - PopupMenuButton( + M2PopupMenuButton( onSelected: (String choice) async { switch (choice) { case 'widgets': diff --git a/lib/widgets/log_view.dart b/lib/widgets/log_view.dart index d87f15f8..0ceba4d6 100644 --- a/lib/widgets/log_view.dart +++ b/lib/widgets/log_view.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:matrix/matrix.dart'; +import 'm2_popup_menu_button.dart'; + class LogViewer extends StatefulWidget { const LogViewer({Key? key}) : super(key: key); @@ -32,7 +34,7 @@ class LogViewerState extends State { icon: const Icon(Icons.zoom_out_outlined), onPressed: () => setState(() => fontSize--), ), - PopupMenuButton( + M2PopupMenuButton( itemBuilder: (context) => Level.values .map((level) => PopupMenuItem( value: level, diff --git a/lib/widgets/m2_popup_menu_button.dart b/lib/widgets/m2_popup_menu_button.dart new file mode 100644 index 00000000..edbe1b9e --- /dev/null +++ b/lib/widgets/m2_popup_menu_button.dart @@ -0,0 +1,46 @@ +import 'package:flutter/material.dart'; + +class M2PopupMenuButton extends StatelessWidget { + final List> Function(BuildContext) itemBuilder; + final T? initialValue; + final void Function(T)? onSelected; + final void Function()? onCanceled; + final Widget? icon; + final Color? color; + final Widget? child; + + const M2PopupMenuButton({ + Key? key, + required this.itemBuilder, + this.initialValue, + this.onSelected, + this.onCanceled, + this.icon, + this.color, + this.child, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + return Theme( + data: theme.copyWith( + useMaterial3: false, + popupMenuTheme: PopupMenuThemeData( + color: theme.colorScheme.surface, + elevation: theme.appBarTheme.scrolledUnderElevation, + textStyle: theme.textTheme.bodyText1, + ), + ), + child: PopupMenuButton( + itemBuilder: itemBuilder, + initialValue: initialValue, + onSelected: onSelected, + onCanceled: onCanceled, + icon: icon, + color: color, + child: child, + ), + ); + } +}