相关疑难解决方法(0)

Flutter-长按PopupMenu

我正在制作图片库,我需要用户能够长按图片以显示弹出菜单,该菜单可使他删除该图片。

到目前为止,我的代码:

  return GestureDetector(
    onLongPress: () {
      showMenu(
        items: <PopupMenuEntry>[
          PopupMenuItem(
            value: this._index,
            child: Row(
              children: <Widget>[
                Icon(Icons.delete),
                Text("Delete"),
              ],
            ),
          )
        ],
        context: context,
      );
    },
    child: Image.memory(
      this._asset.thumbData.buffer.asUint8List(),
      fit: BoxFit.cover,
      gaplessPlayback: true,
    ),
  );
Run Code Online (Sandbox Code Playgroud)

产生:

但是,当调用longPress函数时,我无法找出如何完全删除图像的小部件。怎么做?

dart flutter

5
推荐指数
4
解决办法
5715
查看次数

如何设置 Flutter showMenu 起点

我想知道如何更改 的原点popUpMenu,在底部应用栏正上方启动弹出窗口,无论项目数如何。与屏幕右端对齐。类似的东西(例如)

Positioned(right: 0, bottom: bottomAppBarHeight)
Run Code Online (Sandbox Code Playgroud)

这是popUpMenu我想要实现的设计布局的截图:

设计

这是当前放置的屏幕截图popUpMenu(请忽略其他设计差异,因为它们无关紧要):

实际的

使用的代码如下:

                      onPressed: () {
                        final RelativeRect position =
                            buttonMenuPosition(context);
                        showMenu(context: context, position: position, items: [
                          PopupMenuItem<int>(
                            value: 0,
                            child: Text('Working a lot harder'),
                          ),
                          PopupMenuItem<int>(
                            value: 1,
                            child: Text('Working a lot less'),
                          ),
                          PopupMenuItem<int>(
                            value: 1,
                            child: Text('Working a lot smarter'),
                          ),
                        ]);
                      },
Run Code Online (Sandbox Code Playgroud)

buttonMenuPosition函数的代码:

RelativeRect buttonMenuPosition(BuildContext context) {
    final bool isEnglish =
        LocalizedApp.of(context).delegate.currentLocale.languageCode == 'en';
    final RenderBox bar = context.findRenderObject() as RenderBox;
    final …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-layout

4
推荐指数
2
解决办法
5811
查看次数

标签 统计

flutter ×2

dart ×1

flutter-layout ×1