Flutter - PopupMenuButton Change Icon
The PopupMenuButton class allows us to display 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. The flutter
developers can provide one of a child or an icon but not both. If developers
provide an icon then PopupMenuButton behaves like an IconButton. If both child
and icon are null, then a standard overflow icon is created depending on the
platform.
The following flutter app development tutorial will demonstrate how to set or change the PopupMenuButton widget’s icon. Here we used the PopupMenuButton class’s icon property to change the default icon of the PupupMenuButton widget. Here we also change the default color of the PopupMenuButton widget’s replaced icon.
The PopupMenuButton class’s icon property value is a widget that is the icon used for this button and the button will behave like an IconButton.
The Icon class represents a graphical icon widget drawn with a glyph from a font described in an IconData such as material's predefined IconDatas in Icons. Icons are not interactive.
The Icon class icon property value is an IconData instance that is the icon to display. The available icons are described in Icons. The Icons class is the identifier for the supported material icons. The Icon class color property value is a Color object that is the color to use when drawing the icon.
So finally, the flutter app developers can change the PopupMenuButton widget’s default icon using its icon property. They also can change the icon’s default color.
The following flutter app development tutorial will demonstrate how to set or change the PopupMenuButton widget’s icon. Here we used the PopupMenuButton class’s icon property to change the default icon of the PupupMenuButton widget. Here we also change the default color of the PopupMenuButton widget’s replaced icon.
The PopupMenuButton class’s icon property value is a widget that is the icon used for this button and the button will behave like an IconButton.
The Icon class represents a graphical icon widget drawn with a glyph from a font described in an IconData such as material's predefined IconDatas in Icons. Icons are not interactive.
The Icon class icon property value is an IconData instance that is the icon to display. The available icons are described in Icons. The Icons class is the identifier for the supported material icons. The Icon class color property value is a Color object that is the color to use when drawing the icon.
So finally, the flutter app developers can change the PopupMenuButton widget’s default icon using its icon property. They also can change the icon’s default color.
main.dart
import 'package:flutter/material.dart';
void main(){
runApp(
MaterialApp(
theme: ThemeData(primarySwatch: Colors.green),
home: Scaffold(
appBar: AppBar(
title: const Text("PopupMenuButton Icon"),
actions: [
PopupMenuButton(
color: Colors.blueGrey.shade50,
offset: const Offset(0, 56),
icon: const Icon(
Icons.more_horiz,
color: Colors.black87
),
itemBuilder: (context) => [
const PopupMenuItem(child: Text("First Item")),
const PopupMenuItem(child: Text("Second Item")),
const PopupMenuItem(child: Text("Third Item"))
]
)
]
)
)
)
);
}