Dialog.dart 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import 'package:flutter/material.dart';
  2. // void showSuccess(text) {
  3. // }
  4. void showCustomDialog(context, text, {String title, bool isCancel = false, String submitText = '确认', OnTapHomeMenu onsubmit, OnTapHomeMenu oncancel}) {
  5. Navigator.of(context).push(
  6. PageRouteBuilder(
  7. opaque: false,
  8. transitionDuration: Duration(milliseconds: 300),
  9. transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
  10. return FadeTransition(
  11. opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
  12. child: child,
  13. );
  14. },
  15. pageBuilder: (BuildContext context, _, __) {
  16. return LoadingDialog(title: title, text: text, submitText: submitText, cancel: isCancel, onsubmit: onsubmit, oncancel: oncancel);
  17. },
  18. ),
  19. );
  20. }
  21. typedef OnTapHomeMenu = void Function();
  22. // ignore: must_be_immutable
  23. class LoadingDialog extends Dialog {
  24. String title;
  25. String text;
  26. String submitText;
  27. bool cancel = false;
  28. OnTapHomeMenu onsubmit = () {};
  29. OnTapHomeMenu oncancel = () {};
  30. LoadingDialog({Key key, @required this.text, this.cancel, this.onsubmit, this.oncancel, this.title, this.submitText}) : super(key: key);
  31. @override
  32. Widget build(BuildContext context) {
  33. return WillPopScope(
  34. child: Scaffold(
  35. backgroundColor: Color(0xb3000000),
  36. body: Container(
  37. child: SizedBox.expand(
  38. child: UnconstrainedBox(
  39. child: Container(
  40. width: 270,
  41. // padding: EdgeInsets.symmetric(horizontal: 20, vertical: 25),
  42. decoration: BoxDecoration(color: Color(0xE6293559), border: Border.all(width: 1, color: Color(0xFF1990F8))),
  43. child: Stack(
  44. children: <Widget>[
  45. Padding(
  46. padding: EdgeInsets.symmetric(horizontal: 20, vertical: 25),
  47. child: Column(
  48. mainAxisAlignment: MainAxisAlignment.center,
  49. children: <Widget>[
  50. Text(title ?? '提示', style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold)),
  51. Container(
  52. height: 20,
  53. ),
  54. Text(text, style: TextStyle(color: Colors.white, fontSize: 14), textAlign: TextAlign.center),
  55. Container(
  56. height: 30,
  57. ),
  58. cancel
  59. ? Row(
  60. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  61. children: <Widget>[
  62. Container(
  63. width: 100,
  64. child: RaisedButton(
  65. elevation: 0,
  66. highlightElevation: 0,
  67. color: Color(0xFF3A3D5C),
  68. highlightColor: Color(0xFF3A3D5C).withOpacity(0.8),
  69. textColor: Colors.white,
  70. child: Text('取消'),
  71. onPressed: () {
  72. Navigator.of(context).pop();
  73. oncancel();
  74. },
  75. ),
  76. ),
  77. Container(
  78. width: 100,
  79. child: RaisedButton(
  80. textColor: Colors.white,
  81. child: Text(submitText),
  82. elevation: 0,
  83. highlightElevation: 0,
  84. onPressed: () {
  85. Navigator.of(context).pop();
  86. onsubmit();
  87. },
  88. ),
  89. )
  90. ],
  91. )
  92. : Container(
  93. width: double.infinity,
  94. child: RaisedButton(
  95. textColor: Colors.white,
  96. child: Text(submitText),
  97. onPressed: () {
  98. Navigator.of(context).pop();
  99. onsubmit();
  100. },
  101. ),
  102. ),
  103. Container(
  104. height: 5,
  105. )
  106. ],
  107. ),
  108. ),
  109. ],
  110. ),
  111. ),
  112. ),
  113. ),
  114. ),
  115. ),
  116. onWillPop: () {
  117. return Future.value(false);
  118. },
  119. );
  120. }
  121. }