sanjay sanju
sanjay sanju

Reputation: 1

How to Customize the popup window in flutter

I want to place that popup menu window above a textfield.

Can anoyne show me how I can achieve this?

Popup menu

child:Container( child: PopupMenuButton( offset: Offset(0,10), child: Image.asset( Images.attachment, height: 24, //color: ColorsBase.darkGrayTextColor, ), itemBuilder: (BuildContext context){ 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,),
            ],
          ),
        )
      ];
    },
  ),

this is the code , 1.thing is i want to customize that popup window to place anywhere in the screen.

Upvotes: 0

Views: 2476

Answers (1)

brendan
brendan

Reputation: 3472

You can acheive with a row. 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')),
                    ],
                  ),
                ),
              ];
            }
          ),
        ],
      ),
    );
  }
}

Upvotes: 1

Related Questions