iOS风格的通用的对话框结构,可指定头、中、尾处的组件。

相关组件

AlertDialog

CupertinoAlertDialog基本使用

【title】 : 顶部组件 【Widget】
【content】 : 内容组件 【Widget】
【actions】 : 顶部文字样式 【List
48.gif

  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. class CustomCupertinoAlertDialog extends StatelessWidget {
  4. @override
  5. Widget build(BuildContext context) {
  6. return Column(
  7. children: <Widget>[
  8. _buildRaisedButton(context),
  9. _buildCupertinoAlertDialog(context),
  10. ],
  11. );
  12. }
  13. Widget _buildRaisedButton(BuildContext context) => RaisedButton(
  14. shape: RoundedRectangleBorder(
  15. borderRadius: BorderRadius.all(Radius.circular(10))),
  16. color: Colors.blue,
  17. onPressed: () {
  18. showDialog(
  19. context: context,
  20. builder: (ctx) => _buildCupertinoAlertDialog(context));
  21. },
  22. child: Text(
  23. 'Just Show It !',
  24. style: TextStyle(color: Colors.white),
  25. ),
  26. );
  27. Widget _buildCupertinoAlertDialog(BuildContext context) {
  28. return Material(
  29. color: Colors.transparent,
  30. child: CupertinoAlertDialog(
  31. title: _buildTitle(context),
  32. content: _buildContent(),
  33. actions: <Widget>[
  34. CupertinoButton(
  35. child: Text("Yes, Delete"),
  36. onPressed: () => Navigator.pop(context),
  37. ),
  38. CupertinoButton(
  39. child: Text("Cancle"),
  40. onPressed: () => Navigator.pop(context),
  41. ),
  42. ]),
  43. );
  44. }
  45. Widget _buildTitle(context) {
  46. return Row(
  47. //标题
  48. children: <Widget>[
  49. Icon(
  50. CupertinoIcons.delete_solid,
  51. color: Colors.red,
  52. ),
  53. Expanded(
  54. child: Text(
  55. 'Delete File',
  56. style: TextStyle(color: Colors.red, fontSize: 20),
  57. )),
  58. InkWell(
  59. child: Icon(CupertinoIcons.clear_thick),
  60. onTap: () => Navigator.pop(context),
  61. )
  62. ]);
  63. }
  64. Widget _buildContent() {
  65. return Padding(
  66. padding: const EdgeInsets.only(top: 18.0),
  67. child: Column(
  68. children: <Widget>[
  69. Text(
  70. ' Hi toly! If you push the conform buttom ,'
  71. ' You will lose this file. Are you sure wand to do that?',
  72. style: TextStyle(color: Color(0xff999999), fontSize: 16),
  73. textAlign: TextAlign.justify,
  74. ),
  75. ],
  76. ),
  77. );
  78. }
  79. }