common_alert_dialog.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  4. import 'package:location/resource/colors.gen.dart';
  5. import 'package:location/utils/common_expand.dart';
  6. class CommonAlertDialog {
  7. static const String _tag = "CommonAlertDialog";
  8. static void show(
  9. {required Widget titleWidget,
  10. required Widget descWidget,
  11. required String cancelText,
  12. required String confirmText,
  13. required VoidCallback cancelOnTap,
  14. required VoidCallback confirmOnTap,
  15. String tag = _tag}) {
  16. SmartDialog.show(
  17. tag: _tag,
  18. builder: (_) {
  19. return _CommonAlertDialog(
  20. titleWidget: titleWidget,
  21. descWidget: descWidget,
  22. cancelText: cancelText,
  23. confirmText: confirmText,
  24. cancelOnTap: cancelOnTap,
  25. confirmOnTap: confirmOnTap);
  26. });
  27. }
  28. static void dismiss({String tag = _tag}) {
  29. SmartDialog.dismiss(tag: _tag);
  30. }
  31. }
  32. class _CommonAlertDialog extends Dialog {
  33. final Widget titleWidget;
  34. final Widget descWidget;
  35. final String cancelText;
  36. final String confirmText;
  37. final VoidCallback cancelOnTap;
  38. final VoidCallback confirmOnTap;
  39. const _CommonAlertDialog({
  40. required this.titleWidget,
  41. required this.descWidget,
  42. required this.cancelText,
  43. required this.confirmText,
  44. required this.cancelOnTap,
  45. required this.confirmOnTap,
  46. });
  47. @override
  48. Widget build(BuildContext context) {
  49. return IntrinsicHeight(
  50. child: Container(
  51. width: 300.w,
  52. decoration: BoxDecoration(
  53. color: Colors.white,
  54. borderRadius: BorderRadius.circular(20.w),
  55. ),
  56. child: Column(
  57. children: [
  58. SizedBox(height: 27.w),
  59. titleWidget,
  60. SizedBox(height: 15.w),
  61. Container(
  62. margin: EdgeInsets.symmetric(horizontal: 28.w),
  63. child: descWidget,
  64. ),
  65. SizedBox(height: 32.w),
  66. Row(
  67. mainAxisAlignment: MainAxisAlignment.center,
  68. children: [
  69. GestureDetector(
  70. onTap: () => cancelOnTap(),
  71. child: Container(
  72. width: 109.w,
  73. height: 43.w,
  74. decoration: BoxDecoration(
  75. borderRadius: BorderRadius.all(Radius.circular(57.w)),
  76. border: Border.all(color: ColorName.black15, width: 1.w),
  77. ),
  78. child: Center(
  79. child: Text(cancelText,
  80. style: TextStyle(
  81. fontSize: 14.sp,
  82. color: '#333333'.color,
  83. fontWeight: FontWeight.bold)),
  84. ),
  85. ),
  86. ),
  87. SizedBox(width: 30.w),
  88. GestureDetector(
  89. onTap: () => confirmOnTap(),
  90. child: Container(
  91. width: 109.w,
  92. height: 43.w,
  93. decoration: BoxDecoration(
  94. color: ColorName.colorPrimary,
  95. borderRadius: BorderRadius.all(Radius.circular(57.w)),
  96. ),
  97. child: Center(
  98. child: Text(confirmText,
  99. style: TextStyle(
  100. fontSize: 14.sp,
  101. color: Colors.white,
  102. fontWeight: FontWeight.bold)),
  103. ),
  104. ),
  105. ),
  106. ],
  107. ),
  108. SizedBox(height: 20.w),
  109. ],
  110. ),
  111. ),
  112. );
  113. }
  114. }