error_dialog.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:get/get.dart';
  4. import 'package:nomo/config/theme/theme_extensions/theme_extension.dart';
  5. import '../../config/translations/strings_enum.dart';
  6. import '../widgets/submit_btn.dart';
  7. class ErrorDialog {
  8. static void show({
  9. String? title,
  10. String? message,
  11. String? buttonText,
  12. VoidCallback? onPressed,
  13. }) {
  14. Get.generalDialog(
  15. pageBuilder: (context, animation, secondaryAnimation) {
  16. return AnimatedBuilder(
  17. animation: animation,
  18. builder: (context, child) {
  19. return Transform.scale(
  20. scale: Tween<double>(begin: 0.3, end: 1.0)
  21. .animate(
  22. CurvedAnimation(
  23. parent: animation,
  24. curve: Curves.elasticOut,
  25. ),
  26. )
  27. .value,
  28. child: Transform.translate(
  29. offset: Offset(
  30. 0,
  31. Tween<double>(begin: 100, end: 0)
  32. .animate(
  33. CurvedAnimation(
  34. parent: animation,
  35. curve: Curves.easeOutCubic,
  36. ),
  37. )
  38. .value,
  39. ),
  40. child: Opacity(
  41. opacity: animation.value,
  42. child: WillPopScope(
  43. onWillPop: () async => false,
  44. child: Dialog(
  45. backgroundColor: Get.reactiveTheme.highlightColor,
  46. shape: RoundedRectangleBorder(
  47. borderRadius: BorderRadius.circular(16),
  48. // side: BorderSide(color: Palette.white.withOpacity(0.12)),
  49. ),
  50. child: Container(
  51. padding: const EdgeInsets.all(24),
  52. decoration: BoxDecoration(
  53. color: Get.reactiveTheme.highlightColor,
  54. borderRadius: BorderRadius.circular(16),
  55. ),
  56. child: Column(
  57. mainAxisSize: MainAxisSize.min,
  58. crossAxisAlignment: CrossAxisAlignment.start,
  59. children: [
  60. Text(
  61. title ?? Strings.failed.tr,
  62. style: TextStyle(
  63. color: Get
  64. .reactiveTheme
  65. .textTheme
  66. .bodyLarge!
  67. .color,
  68. fontSize: 18.sp,
  69. fontWeight: FontWeight.w600,
  70. ),
  71. ),
  72. 16.verticalSpaceFromWidth,
  73. Text(
  74. message ?? Strings.unknownError.tr,
  75. style: TextStyle(
  76. color: Get.reactiveTheme.hintColor,
  77. fontSize: 14.sp,
  78. ),
  79. textAlign: TextAlign.start,
  80. ),
  81. 24.verticalSpaceFromWidth,
  82. SubmitButton(
  83. onPressed: () {
  84. Navigator.of(Get.context!).pop();
  85. onPressed?.call();
  86. },
  87. text: buttonText ?? Strings.ok.tr, // 自定义文本
  88. ),
  89. ],
  90. ),
  91. ),
  92. ),
  93. ),
  94. ),
  95. ),
  96. );
  97. },
  98. );
  99. },
  100. barrierDismissible: false,
  101. );
  102. }
  103. }