Onclick Floating Button Show Alert Dialog Box
Complete Code For Onclick Floating Button Show Alert Dialog Box In Flutter
main.dart
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.red,
),
home: MyHomePage(title: 'Onclick Floting Button Show AlertBox'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
void _showDialog() {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Row(
children:[
IconButton(icon: Icon(Icons.notifications_none,size: 25,color: Colors.red,),onPressed: () {},),
Text(' Alert Dialog.',style: TextStyle(color:Colors.red),)
]
),
content: Text("Are You Sure Want To Proceed?"),
actions: <Widget>[
FlatButton(
child: Text("CANCEL",style: TextStyle(color:Colors.red),),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Push the FAB to display a dialog.',
),
],
),
),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.red,
onPressed: _showDialog,
tooltip: 'Show Dialog',
child: Icon(Icons.close,),
),
);
}
}