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 Width")
),
body: bodyContent()
);
}
bodyContent(){
return Center(
child: ElevatedButton(
child: const Text("Show Dialog"),
onPressed: (){
showAlertDialog();
},
),
);
}
showAlertDialog(){
showDialog(
context: context,
builder: (BuildContext context){
return Stack(
clipBehavior: Clip.none, alignment: Alignment.center,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width - 16,
height: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.grey[100]
),
padding: const EdgeInsets.fromLTRB(16, 16, 16, 4),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text(
"Are you agree with the terms?",
style: TextStyle(
decoration: TextDecoration.none,
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 30),
Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
TextButton(
onPressed: (){
Navigator.pop(context);
},
child: const Text("No")
),
TextButton(
onPressed: (){
Navigator.pop(context);
},
child: const Text("Yes")
)
],
)
],
)
)
],
);
}
);
}
}
![](https://fluttertuts.wordpress.com/wp-content/uploads/2021/07/fcf23-flutteralertdialogwidth.png)
More flutter tutorials
- flutter – PageView builder
- flutter – AlertDialog example
- flutter – AlertDialog background color
- flutter – AlertDialog height
- flutter – How to change OutlinedButton splash color
- flutter – How to add padding to OutlinedButton
- flutter – OutlinedButton shape
- flutter – How to create circular OutlinedButton
- flutter – OutlinedButton StadiumBorder
- flutter – OutlinedButton full width
- flutter – How to remove IconButton padding
- flutter – IconButton remove splash
- flutter – How to disable an IconButton
- flutter – FloatingActionButton small
- flutter – FloatingActionButton large