Flutter Widget In Detail: AlertDialog
In-Depth Explanation of AlertDialog Widget

Search for a command to run...
In-Depth Explanation of AlertDialog Widget

No comments yet. Be the first to comment.
Lessons from Code, Content, and Consistency

Reliability basics: Outbox pattern + why it matters

Introducing Kafka/Redpanda + move to event-driven workflow

Connect Orders ↔ Inventory (first working service-to-service flow)

Inventory service + gRPC + proto contracts

Yes or No, or If the user clicks on the delete account, we can display a pop up with a password field to make sure that the actual user with his/her password wants to delete his/her account, etc.AlertDialog, SimpleDialog, AboutDialog. But in this blog, I'm going to explain about the AlertDialog only.

But before that, I want to point out one thing, that we have to call the function called
showDialogwhich is required to open the dialog. which goes something like this:showDialog( context: context, builder: (BuildContext context) { return AlertDialog() } )We can call this
showDialogfunction in a button's callback function. For example:ElevatedButton( child: Text("Show AlertDialog"), onPressed: () { showDialog( // ..... ) } )
title:widget as an input. Usually, we give Text() widget to display the title of the alert dialog.Text, we can also provide an Image, Icon, etc.showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text("Hello AlertDialog"), // Icon(Icons.home) or any kind of widget...
);
}
);

titleStyle:title as per our requirement.TextStyle() as an input.AlertDialog(
titleTextStyle: TextStyle(color:Colors.red),
title: Text("Hello AlertDialog")
);

titlePadding:EdgeInsets's constructors as an input.titlePaddinggives padding of 24 pixels at the top, the left, and the right of the title. It also offers 20 pixels of padding at the bottom of the title if the content is null.AlertDialog(
titleTextStyle: TextStyle(color:Colors.red),
titlePadding: EdgeInsets.all(20.0),
title: Text("Hello AlertDialog")
);
shape:ShapeBorder. There are many subclasses available : CircleBoder, RoundedRectangleBorder, ContinuousRectangleBorder, BeveledRectangleBorder, Border, BorderDirectional, BeveledRectangleBorder, ContinuousRectangleBorder, StadiumBorder, OutlineInputBorder, UnderlineInputBorder.AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0),
side: BorderSide(width: 16.0, color: Colors.red.shade200),
),
title: Text("Hello AlertDialog")
);

semanticLabel:String as an input.AlertDialog(
semanticLabel: "AlertDialog",
title: Text("Hello AlertDialog")
);
content:AlertDialog(
title: Text("Hello"),
content: Container(
width: 300.0,
height: 200.0,
color: Colors.greenAccent,
child: Center(child: Text("I am content"))
)
);


SingleChildScrollView to make it scrollable.AlertDialog(
title: Text("Hello"),
scrollable: true,
content: Container(
width: 300.0,
height: 150.0,
color: Colors.greenAccent,
child: SingleChildScrollView(
child: Column(
children: [
// multiple childrens
],
)
)
)
);

insetPadding:AlertDialog(
insetPadding: EdgeInsets.all(10.0),
title: Text("Hello"),
content: Container(
width: MediaQuery.of(context).size.width,
height: 200.0,
color: Colors.greenAccent,
child: Column(
children: [
Text("Message body"),
],
)
)
);

elevation:elevation property.24.0.AlertDialog(
elevation: 0.0,
title: Text("Hello AlertDialog"),
);

contentTextStyle:contents' Text widgets by using contentTextStyleAlertDialog(
contentTextStyle:
TextStyle(color:Colors.green,fontWeight:FontWeight.bold),
title: Text("Title"),
content: Text("Message body"),
);

contentPadding:content widgets.AlertDialog(
contentPadding: EdgeInsets.all(50.0),
title: Text("Title"),
content: Text("Message body"),
);

buttonPadding:actionss' widgets.AlertDialog(
buttonPadding: EdgeInsets.all(50.0),
actions: [
ElevatedButton(child:Text("Action Btn"),onPressed:(){}),
ElevatedButton(child:Text("Action Btn 2"),onPressed:(){})
],
title: Text("Title"),
content: Text("Message body"),
);

buttonPadding, output will be :
backgroundColor:ThemeData.dialogBackgroundColorAlertDialog(
backgroundColor: Colors.greenAccent,
title: Text("Title"),
content: Text("Message body"),
);

actions:Yes, No, Submit type of buttons.AlertDialog(
title: const Text('Are you sure ?'),
actions: <Widget>[
ElevatedButton(onPressed: () {}, child: const Text('Yes')),
ElevatedButton(onPressed: () {}, child: const Text('No')),
],
);

actionsPadding:AlertDialog(
title: const Text('Title'),
content: Container(width: 100, height: 100, color: Colors.green),
actions: <Widget>[
ElevatedButton(onPressed: () {}, child: const Text('Button 1')),
ElevatedButton(onPressed: () {}, child: const Text('Button 2')),
],
actionsPadding: const EdgeInsets.symmetric(horizontal: 8.0),
);

actionsOverflowButtonSpacing:actions overflows horizontally.actions do not fit into a single row, they are arranged into a column.AlertDialog(
actionsOverflowButtonSpacing: 10.0,
title: const Text('Title'),
actions: <Widget>[
ElevatedButton(onPressed: () {}, child: const Text('Button 1')),
ElevatedButton(onPressed: () {}, child: const Text('Button 2')),
ElevatedButton(onPressed: () {}, child: const Text('Button 3')),
ElevatedButton(onPressed: () {}, child: const Text('Button 4')),
ElevatedButton(onPressed: () {}, child: const Text('Button 5')),
],
content:Container(width:300.0,height:200.0,color:Colors.greenAccent)
);

actionsOverflowDirection:actionsOverflowDirection: VerticalDirection.up: Which arranges the actions in an upward direction.actionsOverflowDirection: VerticalDirection.down (default): Which arranges the actions in downward direction.AlertDialog(
actionsOverflowDirection: VerticalDirection.up,
actionsOverflowButtonSpacing: 10.0,
title: const Text('Title'),
actions: <Widget>[
ElevatedButton(onPressed: () {}, child: const Text('Button 1')),
ElevatedButton(onPressed: () {}, child: const Text('Button 2')),
ElevatedButton(onPressed: () {}, child: const Text('Button 3')),
ElevatedButton(onPressed: () {}, child: const Text('Button 4')),
ElevatedButton(onPressed: () {}, child: const Text('Button 5')),
],
content:Container(width:300.0,height:200.0,color:Colors.greenAccent)
);

actionsOverflowButtonSpacings' results and this one. You can clearly see the difference.
Previous Blog : Widget In Detail - AbsorbPointer & IgnorePointer