123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- // ignore_for_file: constant_identifier_names
- import 'package:flutter/material.dart';
- import 'package:flutter_easyloading/flutter_easyloading.dart';
- import 'package:get/get.dart';
- ///弹出框位置
- enum PromptBoxSnackbarPosition {
- //上部弹出
- Top,
- //底部弹出
- Bottom,
- }
- ///弹出框
- class PromptBox {
- PromptBox._();
- static void init() {
- EasyLoading.instance
- ..displayDuration = const Duration(milliseconds: 2500)
- ..indicatorType = EasyLoadingIndicatorType.ring
- ..loadingStyle = EasyLoadingStyle.custom
- ..indicatorSize = 35.0
- ..lineWidth = 2
- ..radius = 10.0
- ..progressColor = Colors.white
- ..backgroundColor = Colors.black.withOpacity(0.7)
- ..indicatorColor = Colors.white
- ..textColor = Colors.white
- ..fontSize = 16
- ..maskColor = Colors.black.withOpacity(0.6)
- ..successWidget = const Icon(Icons.done, color: Colors.green, size: 35)
- ..errorWidget = const Icon(Icons.close, color: Colors.red, size: 35)
- ..userInteractions = true
- ..dismissOnTap = false;
- }
- static bool _enable = true;
- static void $SetEnable(bool val) {
- _enable = val;
- }
- /// 等待提示
- ///
- /// [text] 自定义提示文案
- static void loading([String? text]) {
- if (!_enable) return;
- _setLoadingStyle();
- EasyLoading.show(
- // indicator: LoadingWidget(text: text ?? '${i18nBook.common.loading.t}...'),
- indicator: SizedBox(
- width: 120,
- height: 80,
- child: Center(
- child: Column(
- children: [
- const CircularProgressIndicator(),
- if (text != null) ...[
- const SizedBox(height: 12),
- Text(
- text,
- style: TextStyle(
- color: Colors.grey.shade700,
- fontSize: 18,
- fontWeight: FontWeight.bold,
- ),
- ),
- ],
- ],
- ),
- ),
- ),
- maskType: EasyLoadingMaskType.custom,
- status: "",
- );
- }
- /// 轻提示
- ///
- /// [text] 提示内容
- static void toast(String text) {
- if (!_enable) return;
- _resetStyle();
- EasyLoading.showToast(text);
- }
- /// 成功提示
- ///
- /// [text] 自定义提示文案
- static void success(String text) {
- if (!_enable) return;
- _resetStyle();
- EasyLoading.showSuccess(text);
- }
- /// 错误提示
- ///
- /// [text] 自定义提示文案
- static void error(String text) {
- if (!_enable) return;
- _resetStyle();
- EasyLoading.showError(text);
- }
- /// 停止提示
- static void dismiss() {
- EasyLoading.instance.userInteractions = true;
- EasyLoading.dismiss();
- }
- /// 提示框(带标题)
- ///
- /// [message] 提示内容
- ///
- /// [title] 标题
- ///
- /// [position] 弹出位置
- static void snackbar(
- String message, {
- String? title,
- PromptBoxSnackbarPosition position = PromptBoxSnackbarPosition.Top,
- }) {
- final isTop = PromptBoxSnackbarPosition.Top == position;
- Get.snackbar(
- title ?? "提示",
- message,
- maxWidth: 400,
- snackPosition: isTop ? SnackPosition.TOP : SnackPosition.BOTTOM,
- margin: isTop
- ? const EdgeInsets.only(top: 36)
- : const EdgeInsets.only(bottom: 48),
- );
- }
- static void _setLoadingStyle() {
- EasyLoading.instance
- ..userInteractions = false
- ..backgroundColor = Colors.transparent
- ..maskColor = Colors.black.withOpacity(0.08)
- ..boxShadow = <BoxShadow>[];
- }
- static void _resetStyle() {
- EasyLoading.instance
- ..backgroundColor = Colors.black.withOpacity(0.7)
- ..maskColor = Colors.black.withOpacity(0.6)
- // 默认不屏蔽用户交互
- ..maskType = EasyLoadingMaskType.none
- ..boxShadow = null;
- }
- }
|