Create Pop up menu/ DropDown menu and Alert dialog in flutter

 Aim : Create Pop up menu/ DropDown menu and AlertDialog in flutter

Pop up menu/ DropDown menu

Code :

import 'package:flutter/material.dart';

void main() {

runApp(const MyApp());

}

class MyApp extends StatelessWidget {

const MyApp({super.key});

// This widget is the root of your application.

@override

Widget build(BuildContext context) {

return MaterialApp(

title: 'Flutter Demo',

theme: ThemeData(

primarySwatch: Colors.blue,

),

home: MyHomePage(),

);

}

}

class MyHomePage extends StatefulWidget {

@override

State<StatefulWidget> createState() {

// TODO: implement createState

return PopUpMenu();

}

}

class PopUpMenu extends State<MyHomePage> {

@override

Widget build(BuildContext context) {

// TODO: implement build

return Scaffold(

appBar: AppBar(actions: [

PopupMenuButton(

itemBuilder: (context) => [

PopupMenuItem(

child: Row(

children: [

Icon(

Icons.share,

color: Colors.black,

),

Text('share')

],

)),

PopupMenuItem(

child: Row(

children: [

Icon(

Icons.download,

color: Colors.black,

),

Text('Downloads')

],

)),

PopupMenuItem(

child: Row(

children: [

Icon(

Icons.save,

color: Colors.black,

),

Text('save')

],

)),

PopupMenuItem(

child: Row(

children: [

Icon(

Icons.settings,

color: Colors.black,

),

Text('settings')

],

)),

],

child: Icon(Icons.more_vert),

)

]),

);

}

}


AlertDialog:

Code:

import 'package:flutter/material.dart';

void main() {

runApp(const MyApp());

}

class MyApp extends StatelessWidget {

const MyApp({super.key});

// This widget is the root of your application.

@override

Widget build(BuildContext context) {

return MaterialApp(

debugShowCheckedModeBanner: false,

title: 'Flutter Demo',

theme: ThemeData(

primarySwatch: Colors.blue,

),

home: MyHomePage(),

);

}

}

class MyHomePage extends StatefulWidget {

@override

State<StatefulWidget> createState() {

// TO DO: implement createState

return _MyHomePage();

}

}

class _MyHomePage extends State<MyHomePage> {

@override

Widget build(BuildContext context) {

// TODO: implement build

return Scaffold(

appBar: AppBar(

title: Text('hello TYIT'),

),

body: Center(

child: ElevatedButton(

onPressed: () {

showDialog(

context: context,

builder: (context) {

return Container(

child: AlertDialog(actions: [

Title(color: Colors.red, child: Text('Email sent')),

TextButton(

onPressed: () {

Navigator.pop(context);

},

child: Text('ok'))

]),

);

});

},

child: Text('send email'),

),

),

);

}

}

Comments