Dialog.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. color: Color(0xFF3A3D5C),
  66. highlightColor: Color(0xFF3A3D5C).withOpacity(0.8),
  67. textColor: Colors.white,
  68. child: Text('取消'),
  69. onPressed: () {
  70. Navigator.of(context).pop();
  71. oncancel();
  72. },
  73. ),
  74. ),
  75. Container(
  76. width: 100,
  77. child: RaisedButton(
  78. textColor: Colors.white,
  79. child: Text(submitText),
  80. onPressed: () {
  81. Navigator.of(context).pop();
  82. onsubmit();
  83. },
  84. ),
  85. )
  86. ],
  87. )
  88. : Container(
  89. width: double.infinity,
  90. child: RaisedButton(
  91. textColor: Colors.white,
  92. child: Text(submitText),
  93. onPressed: () {
  94. Navigator.of(context).pop();
  95. onsubmit();
  96. },
  97. ),
  98. ),
  99. Container(
  100. height: 5,
  101. )
  102. ],
  103. ),
  104. ),
  105. ],
  106. ),
  107. ),
  108. ),
  109. ),
  110. ),
  111. ),
  112. onWillPop: () {
  113. return Future.value(false);
  114. },
  115. );
  116. }
  117. }