Modal.dart 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/widgets.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. class Dialog extends StatelessWidget {
  5. String title;
  6. String type;
  7. String? message;
  8. Widget? content;
  9. VoidCallback? onConfirm;
  10. VoidCallback? onCancel;
  11. Dialog({Key? key,
  12. this.type = 'alert',
  13. required this.title,
  14. this.message,
  15. this.content,
  16. this.onConfirm,
  17. this.onCancel,
  18. }): super(key: key);
  19. Widget _confirmBtn() {
  20. return ElevatedButton(
  21. child: const Text("确定"),
  22. style: ElevatedButton.styleFrom(
  23. primary: const Color(0xFFFF703B),
  24. textStyle: TextStyle(color: Colors.white, fontSize: 20.sp, letterSpacing: 5.sp),
  25. elevation: 0,
  26. minimumSize: Size(90.w, 49.w),
  27. shape: RoundedRectangleBorder(
  28. borderRadius: BorderRadius.all(Radius.circular(24.5.w)),
  29. )
  30. ),
  31. onPressed: onConfirm,
  32. );
  33. }
  34. Widget _cancelBtn() {
  35. return ElevatedButton(
  36. child: const Text("取消"),
  37. style: ElevatedButton.styleFrom(
  38. primary: Colors.transparent,
  39. textStyle: TextStyle(color: const Color(0xFFFF703B), fontSize: 20.sp, letterSpacing: 5.sp),
  40. elevation: 0,
  41. minimumSize: Size(90.w, 49.w),
  42. shape: RoundedRectangleBorder(
  43. side: const BorderSide(color: Color(0xFFFF703B), width: 2.0),
  44. borderRadius: BorderRadius.all(Radius.circular(24.5.w)),
  45. )
  46. ),
  47. onPressed: onCancel,
  48. );
  49. }
  50. Widget _alert() {
  51. return SimpleDialog(
  52. title: Text(title),
  53. children: [
  54. if (null != message) Text(message!),
  55. if (null != content) content!,
  56. Center(
  57. child: _confirmBtn(),
  58. )
  59. ]
  60. );
  61. }
  62. Widget _dialog() {
  63. return SimpleDialog(
  64. title: Text(title),
  65. children: [
  66. if (null != message) Text(message!),
  67. if (null != content) content!,
  68. Row(
  69. children: [
  70. Center(
  71. child: _confirmBtn(),
  72. ),
  73. Center(
  74. child: _cancelBtn(),
  75. )
  76. ],
  77. )
  78. ]
  79. );
  80. }
  81. @override
  82. Widget build(BuildContext context) {
  83. return type == 'alert' ? _alert() : _dialog();
  84. }
  85. }