// Author: fengshengxiong
// Date: 2024/5/7
// Description: 加载、进度、提示框

import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:tone_snap/res/themes/app_colors.dart';

class BaseEasyLoading {
  static void configLoading() {
    EasyLoading.instance
      // 自定义加载样式
      ..loadingStyle = EasyLoadingStyle.custom
      ..indicatorType = EasyLoadingIndicatorType.ring
      ..indicatorSize = 30
      ..lineWidth = 3
      ..textColor = seedColor
      ..indicatorColor = seedColor
      ..progressColor = seedColor
      ..backgroundColor = scaffoldBgColor.withOpacity(0.8)
      ..maskColor = Colors.amber
      ..boxShadow = <BoxShadow>[]
      // 当loading展示的时候，是否允许用户操作.
      ..userInteractions = false
      // 点击背景是否关闭.
      ..dismissOnTap = false;
  }

  static void toast(String? value, {bool? dismissOnTap, bool show = true}) {
    EasyLoading.instance.userInteractions = true;
    if (show && value != null) {
      EasyLoading.showToast(
        value,
        dismissOnTap: dismissOnTap,
        maskType: EasyLoadingMaskType.none,
      );
    }
  }

  static void loading({
    String? value,
    bool? dismissOnTap,
    bool show = true,
  }) {
    EasyLoading.instance.userInteractions = false;
    if (show) EasyLoading.show(status: value, dismissOnTap: false);
  }

  static void dismiss({bool dismiss = true}) {
    if (dismiss) EasyLoading.dismiss();
  }
}
