Bra*_*ker 6 flutter flutter-layout
我想将菜单定位PopupMenuButton到应用程序的侧面,但它总是与侧面留下约 10 个逻辑像素的间隙:

我已经尝试给该属性赋予offset负值dx,但这似乎没有任何作用。据我所知,没有其他属性可以PopupMenuButton更改菜单的位置。
菜单如何准确定位在侧面?我在这里遗漏了一些明显的东西吗?
顺便说一句:PopupMenuButton位于AppBara 的中Scaffold。
这是我的代码PopupMenuButton:
PopupMenuButton(
color: cardBackground,
elevation: 0.0,
shape: RoundedRectangleBorder(
side: BorderSide(
width: 0.5,
color: cardText,
)),
padding: EdgeInsets.all(0.0),
offset: Offset(-10.0, kToolbarHeight),
onSelected: (value) => doPaletteAction(value),
itemBuilder: (BuildContext context) => createPopUpItems(),
icon: Icon(
Icons.format_list_bulleted_rounded,
color: appBarIconButtons,
)
)
Run Code Online (Sandbox Code Playgroud)
Pav*_*vel 10
材质弹出菜单边距是硬编码的:PopupMenuButton > PopupMenuButtonState > showMenu > _PopupMenuRoute > _PopupMenuRouteLayout > _kMenuScreenPadding = 8.0
你能做的是
打开本地 popup_menu.dart 源文件(PopupMenuButton在 IDE 中按住 Ctrl 键单击)
将8.0替换为0.0,进行热重载,观察变化
请记住回滚源以保持一致的行为
将文件复制到您的项目中,进行修复
同时删除相对导入并添加import 'package:flutter/material.dart';
然后使用固定的“叉子”而不是原来的:
import 'package:myapp/popup_menu.dart' as my_popup_menu;
Scaffold(
appBar: AppBar(
elevation: 0,
leading: my_popup_menu.PopupMenuButton(
elevation: 0,
shape: Border.all(width: 0.5),
offset: Offset(0, kToolbarHeight),
itemBuilder: (context) => [
my_popup_menu.PopupMenuItem(
child: Text('PopupMenuItem'),
),
],
),
),
)
Run Code Online (Sandbox Code Playgroud)