Dialog.dart 6.1 KB

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