Dialog.dart 7.1 KB

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