组件
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'AlertDialog组件示例',
home: Scaffold(
appBar: AppBar(
title: Text('AlertDialog组件示例'),
),
body: Center(
//添加对话框
child: AlertDialog(
//对话框标题
title: Text('提示'),
//对话框内容部分
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('是否要删除?'),
Text('一旦删除数据不可恢复!'),
],
),
),
//对话框操作按钮
actions: <Widget>[
FlatButton(
child: Text('确定'),
onPressed: () {},
),
FlatButton(
child: Text('取消'),
onPressed: () {},
),
],
),
),
),
);
}
}
使用
return showDialog(
context: context,
builder: (context) => AlertDialog(
content: Text('是否退出'),
actions: <Widget>[
FlatButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text("取消"),
),
FlatButton(
onPressed: () => Navigator.of(context).pop(true),
child: Text("确定"),
)
],
));
网友评论