notice<T> static method
Future<T?>
notice<T>(
- BuildContext context, {
- required String title,
- required String content,
- String buttonName = "Got it",
- VoidCallback? onPressed,
- double indent = 28,
- bool? dark,
通知,公告。
用途
- 提示信息
- 展示内容
- 展示说明
参数 |参数名|描述|是否必须|
- context 上下文
- title 信息标题
- content 信息内容
- buttonName 按钮文字。
- onPressed 按钮点击事件响应。
- indent 排版,左边缩进的距离。
- dark 是否强制指定夜间模式或者白天模式,不设置使用系统默认。
Implementation
static Future<T?> notice<T>(
BuildContext context, {
required String title,
required String content,
String buttonName = "Got it",
VoidCallback? onPressed,
double indent = 28,
bool? dark,
}) {
// 取宽,屏幕的60%用于对话框。
double _width = MediaQuery.of(context).size.width * 0.72;
bool _dark = dark ?? (Theme.of(context).brightness == Brightness.dark);
return showDialog<T>(
context: context,
// Color(0x9eB2EbF2) 忧郁蓝
barrierColor: _dark ? Color(0xaa000000) : Color(0x9effffff),
builder: (BuildContext context) {
return Dialog(
backgroundColor: _dark ? Colors.black45 : Colors.white60,
// 对话框区域背景色
elevation: 12.0,
insetPadding: EdgeInsets.zero,
clipBehavior: Clip.hardEdge,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: _width,
padding: EdgeInsets.fromLTRB(indent, 28.0, 8.0, 8.0),
child: Text(
title,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: _dark ? Colors.white : Colors.black87),
),
),
SizedBox(
width: _width,
child: Divider(
height: 18,
thickness: 1.8,
indent: indent,
color: _dark ? Colors.white : Colors.black87,
),
),
Container(
width: _width,
padding: EdgeInsets.fromLTRB((indent + 8.0), 8.0, 8.0, 8.0),
child: Text(
content,
style:
TextStyle(color: _dark ? Colors.white : Colors.black87),
),
),
Container(
width: _width,
alignment: Alignment.centerRight,
padding: EdgeInsets.only(right: 8.0),
child: TextButton(
child: Text(
buttonName,
style: TextStyle(
fontSize: 16.0,
),
),
onPressed: onPressed ??
() {
Navigator.of(context).pop();
},
),
)
],
),
);
},
);
}