AlertDialog

import "package:flutter/material.dart";

/// Example 1
// void main()
// {
// runApp(MyApp());
// }
// class MyApp extends StatelessWidget
// {
// MyApp({super.key});
//
// @override
// Widget build(BuildContext context) {
// return MaterialApp(
// title: "AlertDialog Demo",
// debugShowCheckedModeBanner: false,
// theme: ThemeData(
// primarySwatch: Colors.grey,
// ),
// home: AlertDialogDemo(),
// );
// }
// }
// class AlertDialogDemo extends StatefulWidget
// {
// AlertDialogDemo({super.key});
//
// State<AlertDialogDemo> createState() {
// return AlertDialogDemoState();
// }
// }
// class AlertDialogDemoState extends State<AlertDialogDemo>
// {
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// appBar: AppBar(
// title: const Text("AlertDialog Demo"),
// centerTitle: true,
// ),
// body: Center(
// child: ElevatedButton(
// onPressed: () {
// showDialog(
// context: context,
// builder: (BuildContext context) {
// return AlertDialog(
// title: const Text("AlertDialog Title"),
// content: const Text("AlertDialog description"),
// actions: <Widget>[
// ElevatedButton(
// onPressed: (){
// Navigator.pop(context, "Cancel");
// },
// child: const Text("Cancel"),
// ),
// ElevatedButton(
// onPressed: (){
// Navigator.pop(context, "Ok");
// },
// child: const Text("Ok"),
// ),
// ],
// );
// },
// );
// },
// child: const Text("Show Dialog"),
// ),
// ),
// );
// }
// }

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

@override
Widget build(BuildContext context) {
return MaterialApp(
title: "AlertDialog Practice",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.grey,
),
home: AlertDemo(),
);
}
}
class AlertDemo extends StatelessWidget
{
AlertDemo({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("AlertDialog"),
centerTitle: true,
),
body: Center(
child: ElevatedButton(
onPressed: (){
showDialog(
context: context,
builder: (BuildContext context){
return AlertDialog(
title: const Text("Publish post?", style: TextStyle(fontWeight: FontWeight.bold),),
content: const Text("This will publish this post to your blog."),
actions: <Widget>[
TextButton(
onPressed: (){
Navigator.pop(context);
},
child: const Text("CANCEL", style: TextStyle(color: Colors.black),),
),
TextButton(
onPressed: (){
Navigator.pop(context);
},
child: const Text("CONFIRM", style: TextStyle(color: Colors.orange),),
),
],
);
},
);
},
child: const Text("Show Dialog"),
),
),
);
}
}

Comments

Popular posts from this blog

Pagination with Bloc Pattern in Flutter

Pagination First Practical in Flutter

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter