AlertDialog (showdialog)
Object → DiagnosticableTree → Widget → StatelessWidget → AlertDialog
Property
class Demo extends StatefulWidget {
const Demo({Key key}) : super(key: key);
State<Demo> createState() => _DemoState();
}
class _DemoState extends State<Demo> {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Alert Dialog'),
),
body: Test(),
),
);
}
}
class Test extends StatelessWidget {
const Test({
Key key,
}) : super(key: key);
Widget build(BuildContext context) {
return Center(
child: ElevatedButton(
onPressed: () {
_showdialog(context);
},
child: Text('push')),
);
}
Future<dynamic> _showdialog(BuildContext context) {
return showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text('저녁'),
content: Text('밥 먹을러 갈래?'),
actions: [
ElevatedButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('가자')),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('싫어')),
],
),
);
}
}
스탠다드 하게는 이렇게 구성이된다.
elevation : 입체적으로 보일때(그림자 등등 수정)
backgroundColor : 색을 바꿀수있다. 물론 밑바탕이며 아이콘을 수정하고싶다면, actions의 리스트에서 아이콘 수정을 하면된다.
shape : 박스의 끝부분을 수정할수있다.
class Demo extends StatefulWidget {
const Demo({Key key}) : super(key: key);
State<Demo> createState() => _DemoState();
}
class _DemoState extends State<Demo> {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Alert Dialog'),
),
body: Test(),
),
);
}
}
class Test extends StatelessWidget {
const Test({
Key key,
}) : super(key: key);
Widget build(BuildContext context) {
return Center(
child: ElevatedButton(
onPressed: () {
_showdialog(context);
},
child: Text('push')),
);
}
Future<dynamic> _showdialog(BuildContext context) {
return showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text('저녁'),
content: Text('밥 먹을러 갈래?'),
actions: [
ElevatedButton(
onPressed: () => Navigator.of(context).pop(), child: Text('가자')),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(), child: Text('싫어')),
],
elevation: 10.0,
backgroundColor: Colors.pink,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(32)),
),
),
);
}
}