MenuItemList

 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.";

var info2 = " HyperText Transfer Protocol (HTTP) is a protocol using which hypertext is"
" transferred over the Web. Due to its simplicity, http has been the most widely used protocol"
" for data transfer over the Web but the data (i.e. hypertext) exchanged using http isn’t"
" as secure as we would like it to be. In fact, hyper-text exchanged using http goes as plain"
" text i.e. anyone between the browser and server can read it relatively easily"
" if one intercepts this exchange of data. ";

var info3 = "Hypertext Transfer Protocol Secure (HTTPS) is an extension of the Hypertext"
" Transfer Protocol (HTTP). It is used for secure communication. In HTTPS,"
" the communication protocol is encrypted using Transport Layer Security.";

var info4 = "Wraps platform-specific persistent storage for simple data (NSUserDefaults on iOS and"
" macOS, SharedPreferences on Android, etc.). Data may be persisted to disk asynchronously,"
" and there is no guarantee that writes will be persisted to disk after returning,"
" so this plugin must not be used for storing critical data.";

var info5 = "If you are using shared_preferences from multiple isolates,"
" since each isolate has its own SharedPreferences singleton and cache.";

var info6 = "If you are using shared_preferences in multiple engine instances"
" (including those created by plugins that create background contexts on mobile devices,"
" such as firebase_messaging).";

@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(info);
// return FirstPage(key: GlobalKey(debugLabel: info),);
},
),
);
}
else if(value == 1)
{
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return SecondPage(info2);
},
),
);
}
else if(value == 2)
{
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return ThirdPage(info3);
},
),
);
}
else if(value == 3)
{
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return FourthPage(info4);
},
),
);
}
else if(value == 4)
{
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return FifthPage(info5);
},
),
);
}
else if(value == 5)
{
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return SixthPage(info6);
},
),
);
}
},
),
],
),
);
}
}
class FirstPage extends StatelessWidget
{
FirstPage(this.name,{super.key});

var name;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("First Page"),
centerTitle: true,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("First Page", style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),),
const SizedBox(height: 30.0),
Text(name, style: const TextStyle(fontWeight: FontWeight.bold),),
],
),
),
);
}
}
class SecondPage extends StatelessWidget
{
SecondPage(this.name2, {super.key});

var name2;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Second Page"),
centerTitle: true,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Second Page", style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),),
const SizedBox(height: 30.0),
Text(name2, style: const TextStyle(fontWeight: FontWeight.bold),),
],
),
),
);
}
}
class ThirdPage extends StatelessWidget
{
ThirdPage(this.name3, {super.key});

var name3;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Third Page"),
centerTitle: true,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Third Page", style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),),
const SizedBox(height: 30.0),
Text(name3, style: const TextStyle(fontWeight: FontWeight.bold),),
],
),
),
);
}
}
class FourthPage extends StatelessWidget
{
FourthPage(this.name4, {super.key});

var name4;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Fourth Page"),
centerTitle: true,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Fourth Page", style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),),
const SizedBox(height: 30.0),
Text(name4, style: const TextStyle(fontWeight: FontWeight.bold),),
],
),
),
);
}
}
class FifthPage extends StatelessWidget
{
FifthPage(this.name5, {super.key});

var name5;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Fifth Page"),
centerTitle: true,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Fifth Page", style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),),
const SizedBox(height: 30.0),
Text(name5, style: const TextStyle(fontWeight: FontWeight.bold),),
],
),
),
);
}
}
class SixthPage extends StatelessWidget
{
SixthPage(this.name6, {super.key});

var name6;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Sixth Page"),
centerTitle: true,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Sixth Page", style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),),
const SizedBox(height: 30.0),
Text(name6, style: const TextStyle(fontWeight: FontWeight.bold),),
],
),
),
);
}
}

Comments

Popular posts from this blog

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter

Pagination with Bloc Pattern in Flutter

Pagination First Practical in Flutter