对话框Dialog主要包括AlertDialog 和 SimpleDialog
AlertDialog对话框主要用于可以返回结果。而SimpleDialog可以自己定义样式,如图标,内容等。
Dialogs主要分为三类:
Component | Priority | User action |
---|---|---|
Snackbar | Low priority | Optional: Snackbars disappear automatically |
Banner | Prominent, medium priority | Optional: Banners remain until dismissed by the user, or if the state that caused the banner is resolved |
Dialog | Highest priority | Required: Dialogs block app usage until the user takes a dialog action or exits the dialog (if available) |
它们的优先级不同,使用的场景也不一样。
//网上好的代码段
showDialog(
context: context,
barrierColor: Colors.green,
barrierDissmiss:false,//用户是否可以点击外边将其关闭
builder: (_) => Dialog(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
title: Text(
'smart_select',
style: Theme.of(context).textTheme.headline5,
),
subtitle: Text('by davigmacode'),
trailing: IconButton(
icon: Icon(Icons.close),
onPressed: () => Navigator.pop(context),
),
),
Flexible(
fit: FlexFit.loose,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 15),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'Smart select allows you to easily convert your usual form selects to dynamic pages with grouped radio or checkbox inputs. This widget is inspired by Smart Select component from Framework7',
style: Theme.of(context).textTheme.bodyText2,
),
Container(height: 15),
],
),
),
)
],
),
),
);
对话框的外观也是可以修改的
AlertDialog(
title:Text("Accept?"),
content:Text("Do you accept?),
actions:[
FlatButton('NO'),
FlatButton("Yes"),
],
elevation:24,
BackgroundColor:Colors.blue,
shap:CircleBorder(),//外观是可以修改的
)