Dialog.dart 6.5 KB

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