alert_dialog.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:sport/widgets/button_cancel.dart';
  4. import 'package:sport/widgets/button_primary.dart';
  5. import 'package:sport/widgets/misc.dart';
  6. class CustomAlertDialog extends StatelessWidget {
  7. final String title;
  8. final Widget? child;
  9. final String textCancel;
  10. final String textOk;
  11. final Function ok;
  12. final bool addClose;
  13. final bool isLine;
  14. final ValueNotifier? onChanged;
  15. final bool cancelable;
  16. final Key? okKey;
  17. final Key? cancelKey;
  18. CustomAlertDialog({
  19. this.title = "",
  20. this.child,
  21. this.textCancel = "取消",
  22. this.textOk = "确定",
  23. required this.ok,
  24. this.addClose = false,
  25. this.isLine = false,
  26. this.onChanged,
  27. this.cancelable = true,
  28. this.okKey,
  29. this.cancelKey,
  30. });
  31. @override
  32. Widget build(BuildContext context) {
  33. var _width = MediaQuery.of(context).size.shortestSide * (child != null ? 0.70 : 0.66);
  34. return Material(
  35. type: MaterialType.transparency,
  36. child: Scaffold(
  37. backgroundColor: Colors.transparent,
  38. body: Center(
  39. child: Container(
  40. width: _width,
  41. decoration: BoxDecoration(
  42. borderRadius: BorderRadius.all(Radius.circular(10.0)),
  43. color: Colors.white,
  44. ),
  45. child: Column(
  46. mainAxisSize: MainAxisSize.min,
  47. children: <Widget>[
  48. if (addClose)
  49. Align(
  50. alignment: Alignment.topRight,
  51. child: IconButton(
  52. icon: Image.asset("lib/assets/img/btn_close_big.png"),
  53. onPressed: () => Navigator.pop(context, false),
  54. )),
  55. if (title.isNotEmpty == true)
  56. Stack(
  57. children: <Widget>[
  58. Padding(
  59. padding: EdgeInsets.fromLTRB(
  60. 0,
  61. child != null
  62. ? addClose
  63. ? 0
  64. : 16.0
  65. : 32.0,
  66. 0,
  67. isLine ? 15.0 : 20),
  68. child: Column(
  69. children: <Widget>[
  70. isLine
  71. ? Padding(
  72. child: Text(
  73. title,
  74. style: Theme.of(context).textTheme.headline3,
  75. ),
  76. padding: EdgeInsets.only(top: 5.0, bottom: 8.0, left: 16.0, right: 16.0),
  77. )
  78. : Padding(
  79. padding: const EdgeInsets.symmetric(horizontal: 16.0),
  80. child: Text(
  81. title,
  82. style: Theme.of(context).textTheme.headline3,
  83. ),
  84. ),
  85. if (isLine)
  86. Divider(
  87. endIndent: 20.0,
  88. indent: 20.0,
  89. )
  90. ],
  91. ))
  92. ],
  93. ),
  94. //
  95. if (child != null)
  96. ConstrainedBox(
  97. constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height - 250),
  98. child: SingleChildScrollView(
  99. child: child,
  100. )),
  101. Padding(
  102. padding: const EdgeInsets.fromLTRB(16.0, 20.0, 16.0, 20.0),
  103. child: Row(
  104. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  105. children: <Widget>[
  106. if (cancelable == true)
  107. Expanded(
  108. child: CancelButton(
  109. key: cancelKey,
  110. height: 35,
  111. callback: () {
  112. Navigator.of(context).pop(false);
  113. },
  114. content: textCancel),
  115. ),
  116. if (cancelable == true)
  117. const SizedBox(
  118. width: 20.0,
  119. ),
  120. Expanded(
  121. child: PrimaryButton(
  122. key: okKey,
  123. height: 35,
  124. callback: () {
  125. ok();
  126. },
  127. content: textOk))
  128. ],
  129. ),
  130. )
  131. ],
  132. ),
  133. ),
  134. ),
  135. ),
  136. );
  137. }
  138. }