PopupMenuItemList

 import "package:flutter/material.dart";


/// Example 1
// void main()
// {
// runApp(const MyApp());
// }
// class MyApp extends StatelessWidget
// {
// const MyApp({super.key});
//
// @override
// Widget build(BuildContext context) {
// return MaterialApp(
// title: "MenuItemList",
// debugShowCheckedModeBanner: false,
// theme: ThemeData(
// primarySwatch: Colors.blue,
// ),
// home: const MenuItemListDemo(),
// );
// }
// }
// class MenuItemListDemo extends StatefulWidget
// {
// const MenuItemListDemo({super.key});
//
// State<MenuItemListDemo> createState() {
// return MenuItemListDemoState();
// }
// }
// class MenuItemListDemoState extends State<MenuItemListDemo>
// {
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// appBar: AppBar(
// title: const Text("MenuItemList Demo"),
// actions: <Widget>[
// PopupMenuButton(
// add icon, by default "3 dot" icon
// itemBuilder: (context) {
// return [
// PopupMenuItem<int>(
// value: 0,
// child: Text("My Account"),
// ),
// PopupMenuItem<int>(
// value: 1,
// child: Text("Settings"),
// ),
// PopupMenuItem<int>(
// value: 2,
// child: Text("Logout"),
// ),
// ];
// },
// onSelected: (value) {
// if(value == 0)
// {
// print("My Account menu is selected.");
// }
// else if(value == 1)
// {
// print("Settings menu is selected.");
// }
// else if(value == 2)
// {
// print("Logout menu is selected.");
// }
// },
// ),
// ],
// ),
// // body: Container(),
// );
// }
// }

/// Example 2
void main()
{
runApp(const MyApp());
}
class MyApp extends StatelessWidget
{
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: "PopupMenuItemList demo",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.brown,
),
home: const PopupMenuListDemo(),
);
}
}
class PopupMenuListDemo extends StatefulWidget
{
const PopupMenuListDemo({super.key});

State<PopupMenuListDemo> createState() {
return PopupMenuListDemoState();
}
}
class PopupMenuListDemoState extends State<PopupMenuListDemo>
{
var info = "Flutter widgets are built using a modern framework that takes inspiration from React."
" The central idea is that you build your UI out of widgets. Widgets describe what their view"
" should look like given their current configuration and state. When a widget’s state changes,"
" the widget rebuilds its description, which the framework diffs against the previous description"
" in order to determine the minimal changes needed in the underlying render tree to transition"
" from one state to the next.";

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("PopupMenuList"),
centerTitle: true,
actions: <Widget>[
PopupMenuButton(
// add icon, by default "3 dot" icon
itemBuilder: (context) {
return [
PopupMenuItem<int>(
value: 0,
child: Row(
children: [
Icon(Icons.group, color: Colors.black,),
SizedBox(width: 5.0),
Text("New group"),
],
),
),
PopupMenuItem<int>(
value: 1,
child: Row(
children: [
Icon(Icons.broadcast_on_home, color: Colors.black),
SizedBox(width: 5.0),
Text("New broadcast"),
],
),
),
PopupMenuItem<int>(
value: 2,
child: Row(
children: [
Icon(Icons.linked_camera, color: Colors.black),
SizedBox(width: 5.0),
Text("Linked devices"),
],
),
),
PopupMenuItem<int>(
value: 3,
child: Row(
children: [
Icon(Icons.star, color: Colors.black),
SizedBox(width: 5.0),
Text("Starred messages"),
],
),
),
PopupMenuItem<int>(
value: 4,
child: Row(
children: [
Icon(Icons.payment, color: Colors.black),
SizedBox(width: 5.0),
Text("Payments"),
],
),
),
PopupMenuItem<int>(
value: 5,
child: Row(
children: [
Icon(Icons.settings, color: Colors.black),
SizedBox(width: 5.0),
Text("Settings"),
],
),
),
];
},
onSelected: (value) {
if(value == 0)
{
Navigator.push(
context,
MaterialPageRoute(
builder: (context){
return FirstPage();
// return FirstPage(key: GlobalKey(debugLabel: info),);
},
),
);
}
else if(value == 1)
{
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return SecondPage();
},
),
);
}
else if(value == 2)
{
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return ThirdPage();
},
),
);
}
else if(value == 3)
{
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return FourthPage();
},
),
);
}
else if(value == 4)
{
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return FifthPage();
},
),
);
}
else if(value == 5)
{
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return SixthPage();
},
),
);
}
},
),
],
),
);
}
}
class FirstPage extends StatelessWidget
{
FirstPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("First Page"),
centerTitle: true,
),
body: Center(
child: Text("First Page", style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),),
),
);
}
}
class SecondPage extends StatelessWidget
{
SecondPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Second Page"),
centerTitle: true,
),
body: Center(
child: Text("Second Page", style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),),
),
);
}
}
class ThirdPage extends StatelessWidget
{
ThirdPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Third Page"),
centerTitle: true,
),
body: Center(
child: Text("Third Page", style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),),
),
);
}
}
class FourthPage extends StatelessWidget
{
FourthPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Fourth Page"),
centerTitle: true,
),
body: Center(
child: Text("Fourth Page", style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),),
),
);
}
}
class FifthPage extends StatelessWidget
{
FifthPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Fifth Page"),
centerTitle: true,
),
body: Center(
child: Text("Fifth Page", style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),),
),
);
}
}
class SixthPage extends StatelessWidget
{
SixthPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Sixth Page"),
centerTitle: true,
),
body: Center(
child: Text("Sixth Page", style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),),
),
);
}
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter