fix: Popup menu without elevation

This commit is contained in:
Christian Pauly 2022-09-10 12:11:11 +02:00
commit 92fa413156
10 changed files with 80 additions and 30 deletions

View file

@ -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<ChatSettingsPopupMenu> {
onKeysPressed: _showWidgets,
child: Container(),
),
PopupMenuButton(
M2PopupMenuButton(
onSelected: (String choice) async {
switch (choice) {
case 'widgets':

View file

@ -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<LogViewer> {
icon: const Icon(Icons.zoom_out_outlined),
onPressed: () => setState(() => fontSize--),
),
PopupMenuButton<Level>(
M2PopupMenuButton<Level>(
itemBuilder: (context) => Level.values
.map((level) => PopupMenuItem(
value: level,

View file

@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
class M2PopupMenuButton<T> extends StatelessWidget {
final List<PopupMenuEntry<T>> 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<T>(
itemBuilder: itemBuilder,
initialValue: initialValue,
onSelected: onSelected,
onCanceled: onCanceled,
icon: icon,
color: color,
child: child,
),
);
}
}