common_alert_dialog.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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:keyboard/utils/common_expand.dart';
  5. import '../resource/colors.gen.dart';
  6. import '../utils/styles.dart';
  7. class CommonAlertDialog {
  8. static const String _tag = "CommonAlertDialog";
  9. static void show(
  10. {required Widget titleWidget,
  11. required Widget descWidget,
  12. required String cancelText,
  13. required String confirmText,
  14. required VoidCallback cancelOnTap,
  15. required VoidCallback confirmOnTap,
  16. String tag = _tag}) {
  17. SmartDialog.show(
  18. tag: _tag,
  19. builder: (_) {
  20. return _CommonAlertDialog(
  21. titleWidget: titleWidget,
  22. descWidget: descWidget,
  23. cancelText: cancelText,
  24. confirmText: confirmText,
  25. cancelOnTap: cancelOnTap,
  26. confirmOnTap: confirmOnTap);
  27. });
  28. }
  29. static void dismiss({String tag = _tag}) {
  30. SmartDialog.dismiss(tag: _tag);
  31. }
  32. }
  33. class _CommonAlertDialog extends Dialog {
  34. final Widget titleWidget;
  35. final Widget descWidget;
  36. final String cancelText;
  37. final String confirmText;
  38. final VoidCallback cancelOnTap;
  39. final VoidCallback confirmOnTap;
  40. const _CommonAlertDialog({
  41. required this.titleWidget,
  42. required this.descWidget,
  43. required this.cancelText,
  44. required this.confirmText,
  45. required this.cancelOnTap,
  46. required this.confirmOnTap,
  47. });
  48. @override
  49. Widget build(BuildContext context) {
  50. return Container(
  51. margin: EdgeInsets.symmetric(horizontal: 33.w),
  52. decoration: ShapeDecoration(
  53. color: Colors.white,
  54. shape: RoundedRectangleBorder(
  55. borderRadius: BorderRadius.circular(20.r),
  56. ),
  57. ),
  58. padding: EdgeInsets.symmetric(
  59. horizontal: 16.w,
  60. vertical: 24.w,
  61. ),
  62. child: IntrinsicHeight(
  63. child: Column(
  64. children: [
  65. titleWidget,
  66. SizedBox(height: 20.h),
  67. descWidget,
  68. SizedBox(height: 20.h),
  69. Row(
  70. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  71. children: [
  72. GestureDetector(
  73. onTap: () => cancelOnTap(),
  74. child: Container(
  75. height: 40.h,
  76. width: 128.w,
  77. alignment: Alignment.center,
  78. decoration: ShapeDecoration(
  79. color: const Color(0xFFF5F4F9),
  80. shape: RoundedRectangleBorder(
  81. borderRadius: BorderRadius.circular(50.r),
  82. ),
  83. ),
  84. child: Center(
  85. child: Text(cancelText,
  86. style: Styles.getTextStyleBlack102W500(16.sp),
  87. ),
  88. ),
  89. ),
  90. ),
  91. GestureDetector(
  92. onTap: () => confirmOnTap(),
  93. child: Container(
  94. height: 40.h,
  95. width: 128.r,
  96. alignment: Alignment.center,
  97. decoration: Styles.getActivateButtonDecoration(
  98. 50.r,
  99. ),
  100. child: Center(
  101. child: Text(confirmText,
  102. style: Styles.getTextStyleWhiteW500(16.sp),),
  103. ),
  104. ),
  105. ),
  106. ],
  107. ),
  108. ],
  109. ),
  110. ),
  111. );
  112. }
  113. }