Как настроить всплывающее окно в флаттере - PullRequest
0 голосов
/ 07 января 2020

Я хочу разместить это всплывающее меню над текстовым полем.

Может ли анойн показать мне, как мне этого добиться?

Popup menu

child: Container ( дочерний: PopupMenuButton (смещение: смещение (0,10), дочерний: Image.asset (Images.attachment, высота: 24, // color: ColorsBase.darkGrayTextColor,), itemBuilder: (контекст BuildContext) {return [

        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. я хочу настроить это всплывающее окно для размещения в любом месте экрана.

1 Ответ

0 голосов
/ 07 января 2020

Вы можете достичь с рядом. Горизонтальное выравнивание 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')),
                    ],
                  ),
                ),
              ];
            }
          ),
        ],
      ),
    );
  }
}
...