Dialog.dart 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import 'package:flutter/material.dart';
  2. import 'LinearButton.dart';
  3. // void showSuccess(text) {
  4. // }
  5. class MyDialog {
  6. static Future showDialog(context, text,
  7. {String title, bool isCancel = false, String submitText = '确认', List<Map> textList = const [], OnTapHomeMenu onsubmit, OnTapHomeMenu oncancel}) {
  8. return Navigator.of(context).push(
  9. PageRouteBuilder(
  10. opaque: false,
  11. transitionDuration: Duration(milliseconds: 300),
  12. transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
  13. return FadeTransition(
  14. opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
  15. child: child,
  16. );
  17. },
  18. pageBuilder: (BuildContext context, _, __) {
  19. return LoadingDialog(title: title, text: text, textList: textList, submitText: submitText, cancel: isCancel, onsubmit: onsubmit, oncancel: oncancel);
  20. },
  21. ),
  22. );
  23. }
  24. }
  25. typedef OnTapHomeMenu = void Function();
  26. // ignore: must_be_immutable
  27. class LoadingDialog extends Dialog {
  28. String title;
  29. String text;
  30. String submitText;
  31. bool cancel = false;
  32. OnTapHomeMenu onsubmit = () {};
  33. OnTapHomeMenu oncancel = () {};
  34. List<Map> textList = [];
  35. LoadingDialog({Key key, @required this.text, this.cancel, this.textList, this.onsubmit, this.oncancel, this.title, this.submitText}) : super(key: key);
  36. Widget _text(textList) {
  37. if (textList.length > 0) {
  38. List<TextSpan> _list = [];
  39. for (int i = 0; i < textList.length; i++) {
  40. if (textList[i]["isImportant"]) {
  41. _list.add(TextSpan(
  42. text: textList[i]['value'],
  43. style: TextStyle(
  44. color: Color(0xFFFFB726),
  45. )));
  46. } else {
  47. _list.add(TextSpan(
  48. text: textList[i]['value'],
  49. style: TextStyle(
  50. color: Colors.white,
  51. )));
  52. }
  53. }
  54. return Text.rich(TextSpan(children: _list),textAlign: TextAlign.center,);
  55. } else {
  56. return Container();
  57. }
  58. }
  59. @override
  60. Widget build(BuildContext context) {
  61. return WillPopScope(
  62. child: Scaffold(
  63. backgroundColor: Color(0xCC000000),
  64. body: Container(
  65. child: SizedBox.expand(
  66. child: UnconstrainedBox(
  67. child: Container(
  68. width: 270,
  69. // padding: EdgeInsets.symmetric(horizontal: 20, vertical: 25),
  70. decoration: BoxDecoration(color: Color(0xFF15151D), border: Border.all(width: 1, color: Theme.of(context).primaryColor)),
  71. child: Stack(
  72. children: <Widget>[
  73. Padding(
  74. padding: EdgeInsets.symmetric(horizontal: 20, vertical: 25),
  75. child: Column(
  76. mainAxisAlignment: MainAxisAlignment.center,
  77. children: <Widget>[
  78. Text(title ?? '提示', style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.w600)),
  79. Container(
  80. height: 20,
  81. ),
  82. Text(text, style: TextStyle(color: Colors.white, fontSize: 14), textAlign: TextAlign.center),
  83. _text(textList),
  84. Container(
  85. height: 30,
  86. ),
  87. cancel
  88. ? Row(
  89. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  90. children: <Widget>[
  91. Container(
  92. width: 100,
  93. child: LinearButton(
  94. btntext: '取消',
  95. btnHeight: 36.0,
  96. colorList: [Colors.white, Colors.white],
  97. textColor: Color(0xFF252532),
  98. onTapHomeMenu: () {
  99. Navigator.of(context).pop();
  100. oncancel();
  101. },
  102. ),
  103. ),
  104. Container(
  105. width: 100,
  106. child: LinearButton(
  107. btntext: submitText,
  108. btnHeight: 36.0,
  109. onTapHomeMenu: () {
  110. Navigator.of(context).pop();
  111. onsubmit();
  112. },
  113. )
  114. // RaisedButton(
  115. // textColor: Colors.white,
  116. // child: Text(submitText),
  117. // onPressed: () {
  118. // Navigator.of(context).pop();
  119. // onsubmit();
  120. // },
  121. // ),
  122. )
  123. ],
  124. )
  125. : Container(
  126. width: double.infinity,
  127. child: LinearButton(
  128. btntext: submitText,
  129. btnHeight: 36.0,
  130. onTapHomeMenu: () {
  131. Navigator.of(context).pop();
  132. onsubmit();
  133. },
  134. )
  135. // RaisedButton(
  136. // textColor: Colors.white,
  137. // child: Text(submitText),
  138. // onPressed: () {
  139. // Navigator.of(context).pop();
  140. // onsubmit();
  141. // },
  142. // ),
  143. ),
  144. Container(
  145. height: 5,
  146. )
  147. ],
  148. ),
  149. ),
  150. Positioned(
  151. top: 0,
  152. left: 0,
  153. child: Image.asset(
  154. 'images/tancuang_shang.png',
  155. // width: 131,
  156. ),
  157. ),
  158. Positioned(
  159. bottom: 0,
  160. right: 4,
  161. child: Image.asset(
  162. 'images/tancuang_xia.png',
  163. // width: 148,
  164. ),
  165. ),
  166. ],
  167. ),
  168. ),
  169. ),
  170. ),
  171. ),
  172. ),
  173. onWillPop: () {
  174. return Future.value(false);
  175. },
  176. );
  177. }
  178. }