AlertDialog practice

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 Practice",
// debugShowCheckedModeBanner: false,
// theme: ThemeData(
// primarySwatch: Colors.brown,
// ),
// home: AlertDemo(),
// );
// }
// }
// class AlertDemo extends StatefulWidget
// {
// AlertDemo({super.key});
//
// @override
// State<AlertDemo> createState() {
// return AlertDemoState();
// }
// }
// class AlertDemoState extends State<AlertDemo>
// {
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// appBar: AppBar(
// title: const Text("AlertDialog Demo Practice"),
// centerTitle: true,
// ),
// body: Center(
// child: ElevatedButton(
// onPressed: (){
// showDialog(
// context: context,
// builder: (BuildContext context){
// return AlertDialog(
// title: Text("Delete Contact", style: TextStyle(fontWeight: FontWeight.bold),),
// content: Text("Are you sure ?"),
// actions: <Widget>[
// TextButton(
// onPressed: (){
// Navigator.pop(context);
// },
// child: Text("Cancel"),
// ),
// TextButton(
// onPressed: (){
// Navigator.pop(context);
// },
// child: Text("Yes"),
// ),
// ],
// );
// },
// );
// },
// 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