prompt.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_easyloading/flutter_easyloading.dart';
  3. import 'package:flyinsonolite/infrastructure/scale.dart';
  4. import 'package:flyinsonolite/infrastructure/storage.dart';
  5. ///弹出框位置
  6. enum PromptBoxSnackbarPosition {
  7. //上部弹出
  8. top,
  9. //底部弹出
  10. bottom,
  11. }
  12. ///弹出框
  13. class PromptBox {
  14. PromptBox._();
  15. static void init() {
  16. EasyLoading.instance
  17. ..displayDuration = const Duration(milliseconds: 2000)
  18. ..indicatorType = EasyLoadingIndicatorType.ring
  19. ..loadingStyle = EasyLoadingStyle.custom
  20. ..indicatorSize = 35.s
  21. ..lineWidth = 2.s
  22. ..radius = 10.s
  23. ..progressColor = Colors.white
  24. ..backgroundColor = Storage.currentTheme.themeData.indicatorColor
  25. ..indicatorColor = Colors.white
  26. ..textColor = Colors.white
  27. ..maskColor = Colors.black.withOpacity(0.6)
  28. ..successWidget = Icon(Icons.done, color: Colors.green, size: 35.s)
  29. ..errorWidget = Icon(Icons.close, color: Colors.red, size: 35.s)
  30. ..userInteractions = true
  31. ..fontSize = 24.s
  32. ..dismissOnTap = false
  33. ..progressWidth = 2.s
  34. ..textPadding = EdgeInsets.only(bottom: 10.s)
  35. ..contentPadding = EdgeInsets.symmetric(
  36. vertical: 15.s,
  37. horizontal: 20.s,
  38. );
  39. }
  40. static bool _enable = true;
  41. static void $SetEnable(bool val) {
  42. _enable = val;
  43. }
  44. /// 等待提示
  45. ///
  46. /// [text] 自定义提示文案
  47. //static void loading([String? text]) {
  48. // if (!_enable) return;
  49. // _setLoadingStyle();
  50. // EasyLoading.show(
  51. // indicator: LoadingWidget(text: text ?? '${i18nBook.common.loading.t}...'),
  52. // maskType: EasyLoadingMaskType.custom,
  53. // status: "",
  54. // );
  55. // }
  56. /// 轻提示
  57. ///
  58. /// [text] 提示内容
  59. static void toast(String text) {
  60. if (!_enable) return;
  61. EasyLoading.showToast(text);
  62. }
  63. /// 成功提示
  64. ///
  65. /// [text] 自定义提示文案
  66. static void success(String text) {
  67. if (!_enable) return;
  68. EasyLoading.showSuccess(text);
  69. }
  70. /// 错误提示
  71. ///
  72. /// [text] 自定义提示文案
  73. static void error(String text) {
  74. if (!_enable) return;
  75. EasyLoading.showError(text);
  76. }
  77. /// 停止提示
  78. static void dismiss() {
  79. EasyLoading.instance.userInteractions = true;
  80. EasyLoading.dismiss();
  81. }
  82. /// 提示框(带标题)
  83. ///
  84. /// [message] 提示内容
  85. ///
  86. /// [title] 标题
  87. ///
  88. /// [position] 弹出位置
  89. //static void snackbar(
  90. // String message, {
  91. // String? title,
  92. // PromptBoxSnackbarPosition position = PromptBoxSnackbarPosition.Top,
  93. //}) {
  94. // final isTop = PromptBoxSnackbarPosition.Top == position;
  95. // Get.snackbar(
  96. // title ?? i18nBook.common.tip.t,
  97. // message,
  98. // maxWidth: kIsWeb ? Sizer.ins.size.width - 40 : 400,
  99. // snackPosition: isTop ? SnackPosition.TOP : SnackPosition.BOTTOM,
  100. // margin: isTop
  101. // ? const EdgeInsets.only(top: 36)
  102. // : const EdgeInsets.only(bottom: 48),
  103. // );
  104. //}
  105. }