【问题标题】:How to Customize the popup window in flutter如何在颤振中自定义弹出窗口
【发布时间】:2020-04-24 16:52:04
【问题描述】:

我想将弹出菜单窗口放在文本字段上方。

可以告诉我如何实现这一目标吗?

孩子:容器( 孩子:弹出菜单按钮( 偏移量:偏移量(0,10), 孩子:Image.asset( 图片.附件, 身高:24, //颜色:ColorsBase.darkGrayTextColor, ), itemBuilder:(BuildContext 上下文){ 返回[

        PopupMenuWidget(

          height: 100,
          child: new Row(
            children: <Widget>[
              new IconButton(
                  icon: Icon(Icons.file_upload),
                  onPressed: null),
              SizedBox(width: 10,),
              new IconButton(
                  icon: Icon(Icons.video_call),
                  onPressed: null),
              SizedBox(width: 10,),
              new IconButton(
                  icon: Icon(Icons.audiotrack),
                  onPressed: null),
              SizedBox(width: 10,),
              new IconButton(
                  icon: Icon(Icons.add_location),
                  onPressed: null),
              SizedBox(width: 10,),
              new IconButton(
                  icon: Icon(Icons.contacts),
                  onPressed: null),
              SizedBox(width: 10,),
            ],
          ),
        )
      ];
    },
  ),

这是代码, 1.事情是我想自定义该弹出窗口以放置在屏幕的任何位置。

【问题讨论】:

  • 请添加一些代码示例,社区将无法帮助您仅看到图像。

标签: flutter textfield popupwindow


【解决方案1】:

您可以连续完成。 Horizontal Alignment of PopupMenuEntry

import 'package:flutter/material.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      home: new MyHomePage(),
    );
  }
}

/// An arbitrary widget that lives in a popup menu
class PopupMenuWidget<T> extends PopupMenuEntry<T> {
  const PopupMenuWidget({ Key key, this.height, this.child }) : super(key: key);

  @override
  final Widget child;

  @override
  final double height;

  @override
  bool get enabled => false;

  @override
  _PopupMenuWidgetState createState() => new _PopupMenuWidgetState();
}

class _PopupMenuWidgetState extends State<PopupMenuWidget> {
  @override
  Widget build(BuildContext context) => widget.child;
}


class MyHomePage extends StatelessWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        actions: <Widget>[
          new PopupMenuButton<String>(
            onSelected: (String value) {
              print("You selected $value");
            },
            itemBuilder: (BuildContext context) {
              return [
                new PopupMenuWidget(
                  height: 40.0,
                  child: new Row(
                    children: [
                      new IconButton(
                        icon: new Icon(Icons.add),
                        onPressed: () => Navigator.pop(context, 'add')),
                      new IconButton(
                        icon: new Icon(Icons.remove),
                        onPressed: () => Navigator.pop(context, 'remove')),
                    ],
                  ),
                ),
              ];
            }
          ),
        ],
      ),
    );
  }
}

【讨论】:

    猜你喜欢
    • 2019-06-26
    • 2021-06-29
    • 2020-02-27
    • 2022-08-22
    • 2020-01-23
    • 1970-01-01
    • 2019-05-17
    • 2021-08-29
    • 2013-01-15
    相关资源
    最近更新 更多