123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- import 'package:fis_i18n/i18n.dart';
- import 'package:fis_ui/index.dart';
- import 'package:fis_ui/utils/sizer/sizer.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_easyloading/flutter_easyloading.dart';
- import 'package:get/get.dart';
- import 'package:fis_theme/theme.dart';
- ///弹出框位置
- enum PromptBoxSnackbarPosition {
- //上部弹出
- Top,
- //底部弹出
- Bottom,
- }
- ///弹出框
- class PromptBox {
- PromptBox._();
- static void init() {
- EasyLoading.instance
- ..displayDuration = const Duration(milliseconds: 2000)
- ..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 = FIcon(Icons.done, color: Colors.green, size: 35)
- ..errorWidget = FIcon(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: Theme(
- data: ThemeData.light().copyWith(
- primaryColor: const Color(0xFF4A5468),
- textTheme: TextTheme(
- displayLarge:
- TextStyle(fontFamily: FTheme.ins.localeSetting.fontFamily),
- ),
- ),
- child: LoadingWidget(
- text: text ?? '${i18nBook.common.loading.t}...',
- ),
- ),
- 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,
- Color? textColor = Colors.black,
- Color? backgroundColor,
- Duration? duration = const Duration(seconds: 3),
- PromptBoxSnackbarPosition position = PromptBoxSnackbarPosition.Top,
- }) {
- final isTop = PromptBoxSnackbarPosition.Top == position;
- Get.snackbar(
- title ?? i18nBook.common.tip.t,
- message,
- colorText: textColor,
- duration: duration,
- backgroundColor: backgroundColor,
- animationDuration: const Duration(milliseconds: 800),
- maxWidth: kIsMobile ? Sizer.ins.size.width - 40 : 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)
- ..boxShadow = null;
- }
- }
|