main.dart
import 'package:flutter/material.dart';
void main() => runApp(const FlutterExample());
class FlutterExample extends StatelessWidget {
const FlutterExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Example',
theme: ThemeData(primarySwatch: Colors.pink),
home: const StateExample()
);
}
}
class StateExample extends StatefulWidget {
const StateExample({Key? key}) : super(key: key);
@override
_StateExampleState createState() => _StateExampleState();
}
class _StateExampleState extends State<StateExample> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF5F5F5),
appBar: AppBar(
title: const Text("Flutter - AlertDialog Actions Center")
),
body: bodyContent()
);
}
bodyContent(){
return Center(
child: ElevatedButton(
child: const Text("Show Dialog"),
onPressed: (){
showAlertDialog();
},
),
);
}
showAlertDialog(){
Widget cancelButton = TextButton(
onPressed: (){
Navigator.pop(context);
},
child: const Text("Cancel")
);
Widget positiveButton = TextButton(
onPressed: (){
Navigator.pop(context);
},
child: const Text("Yes")
);
AlertDialog dialog = AlertDialog(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(5),
topRight: Radius.circular(25),
bottomRight: Radius.circular(5),
bottomLeft: Radius.circular(25)
)
),
title: const Text("Lorem Ipsum"),
content: const Text(
"Lorem Ipsum is simply dummy text of the printing and"
" typesetting industry. Lorem Ipsum has been the"
" industry's standard dummy text ever since the 1500s,"
" when an unknown printer took a galley of type and"
" scrambled it to make a type specimen book."
),
actions: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
cancelButton,
const SizedBox(width: 15),
positiveButton
],
),
],
);
showDialog(
context: context,
builder: (BuildContext context){
return dialog;
});
}
}
![](https://fluttertuts.wordpress.com/wp-content/uploads/2021/07/9701a-flutteralertdialogactionscenter.png)
More flutter tutorials
- flutter – PageView builder
- flutter – AlertDialog width
- flutter – AlertDialog height
- flutter – AlertDialog scrollable
- flutter – AlertDialog shape
- flutter – Expanded example
- flutter – Expanded flex
- flutter – Align exact position
- flutter – Container transform rotation
- flutter – BoxDecoration example
- flutter – Chip example
- flutter – Container circle border
- flutter – Container gradient border
- flutter – How to show hide status bar
- flutter – AppBar center title