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

import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

/// EasyLoading配置
void configLoading() {
  EasyLoading.instance
    // loading的样式, 默认[EasyLoadingStyle.dark].
    ..loadingStyle = EasyLoadingStyle.custom
    // loading的指示器类型，默认[EasyLoadingIndicatorType.fadingCircle].
    ..indicatorType = EasyLoadingIndicatorType.ring
    // loading的遮罩类型, 默认[EasyLoadingMaskType.none].
    ..maskType = EasyLoadingMaskType.none
    // toast的位置, 默认 [EasyLoadingToastPosition.center].
    ..toastPosition = EasyLoadingToastPosition.center
    // 动画类型, 默认 [EasyLoadingAnimationStyle.opacity].
    ..animationStyle = EasyLoadingAnimationStyle.opacity
    // 文本的对齐方式 , 默认[TextAlign.center].
    ..textAlign = TextAlign.center
    // 文本的样式 , 默认 null
    ..textStyle = null
    // 指示器的大小, 默认40.0.
    ..indicatorSize = 26.0
    // loading的圆角大小, 默认5.0.
    ..radius = 8.0
    // 文本大小, 默认15.0.
    ..fontSize = 14.0
    // 进度条指示器的宽度, 默认2.0.
    ..progressWidth = 2.0
    // 指示器的宽度, 默认4.0, 仅对[EasyLoadingIndicatorType.ring, EasyLoadingIndicatorType.dualRing]有效.
    ..lineWidth = 2.0
    // [showSuccess] [showError] [showInfo]的展示时间, 默认2000ms.
    ..displayDuration = const Duration(milliseconds: 1000)
    // 动画时间, 默认200ms.
    ..animationDuration = const Duration(milliseconds: 200)
    // 文本的颜色, 仅对[EasyLoadingStyle.custom]有效.
    ..textColor = Colors.black
    // 指示器的颜色, 仅对[EasyLoadingStyle.custom]有效.
    ..indicatorColor = Colors.black
    // 进度条指示器的颜色, 仅对[EasyLoadingStyle.custom]有效.
    ..progressColor = Colors.black
    // loading的背景色, 仅对[EasyLoadingStyle.custom]有效.
    ..backgroundColor = Colors.white
    // 遮罩的背景色, 仅对[EasyLoadingMaskType.custom]有效.
    ..maskColor = Colors.black.withOpacity(0.3)
    // 当loading展示的时候，是否允许用户操作.
    ..userInteractions = false
    // 点击背景是否关闭.
    ..dismissOnTap = false;
}

void toast(String? value, {bool show = true}) {
  if (show && value != null) {
    EasyLoading.showToast(value);
  }
}

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

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