iOS风格的通用的对话框结构,可指定头、中、尾处的组件。
相关组件
CupertinoAlertDialog基本使用
【title】 : 顶部组件 【Widget】
【content】 : 内容组件 【Widget】
【actions】 : 顶部文字样式 【List
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class CustomCupertinoAlertDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
_buildRaisedButton(context),
_buildCupertinoAlertDialog(context),
],
);
}
Widget _buildRaisedButton(BuildContext context) => RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10))),
color: Colors.blue,
onPressed: () {
showDialog(
context: context,
builder: (ctx) => _buildCupertinoAlertDialog(context));
},
child: Text(
'Just Show It !',
style: TextStyle(color: Colors.white),
),
);
Widget _buildCupertinoAlertDialog(BuildContext context) {
return Material(
color: Colors.transparent,
child: CupertinoAlertDialog(
title: _buildTitle(context),
content: _buildContent(),
actions: <Widget>[
CupertinoButton(
child: Text("Yes, Delete"),
onPressed: () => Navigator.pop(context),
),
CupertinoButton(
child: Text("Cancle"),
onPressed: () => Navigator.pop(context),
),
]),
);
}
Widget _buildTitle(context) {
return Row(
//标题
children: <Widget>[
Icon(
CupertinoIcons.delete_solid,
color: Colors.red,
),
Expanded(
child: Text(
'Delete File',
style: TextStyle(color: Colors.red, fontSize: 20),
)),
InkWell(
child: Icon(CupertinoIcons.clear_thick),
onTap: () => Navigator.pop(context),
)
]);
}
Widget _buildContent() {
return Padding(
padding: const EdgeInsets.only(top: 18.0),
child: Column(
children: <Widget>[
Text(
' Hi toly! If you push the conform buttom ,'
' You will lose this file. Are you sure wand to do that?',
style: TextStyle(color: Color(0xff999999), fontSize: 16),
textAlign: TextAlign.justify,
),
],
),
);
}
}