How To Create Popup Menu Button With Icon And Text In Flutter

admin_img Posted By Bajarangi soft , Posted On 27-11-2020

Displays a menu when pressed and calls onSelected when the menu is dismissed because an item was selected. The value passed to onSelected is the value of the selected menu item.One of child or icon may be provided, but not both. If icon is provided, then PopupMenuButton behaves like an IconButton.

How To Create Popup Menu Button With Icon And Text In Flutter

Popup Menu Button With Icon And Text
Complete Code For Popup Menu Button With Icon And Text In Flutter
main.dart

import 'dart:async';
import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}
class MyHomePage extends StatefulWidget {
  final String title;
  MyHomePage({this.title});
  @override
  _MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.lightGreen,
          title: Text(" PopupMenuButton with Icon & Text"),
        ),
        body: Center(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              PopupMenuButton(
                icon: Icon(Icons.person),
                itemBuilder: (context) => [
                  PopupMenuItem(
                    child: Text("Account"),
                  ),
                  PopupMenuItem(
                    child: Text("Change Password"),
                  ),
                  PopupMenuItem(
                    child: Text("Sign Out"),
                  ),
                ],
              ),
              SizedBox(width: 10.0),
              Text("View Account")
            ],
          ),
        ));
  }
}

Related Post