showLoading static method

void showLoading({
  1. required BuildContext context,
  2. Color bgColor = Colors.transparent,
  3. String? text,
  4. Widget? child,
  5. bool isClickDismiss = false,
  6. OnClickDismiss? onClickDismiss,
  7. Duration fadeDuration = const Duration(milliseconds: 350),
})

Implementation

static void showLoading({
  required BuildContext context,
  Color bgColor=Colors.transparent,
  String? text,
  Widget? child,
  bool isClickDismiss = false,
  OnClickDismiss? onClickDismiss,
  Duration fadeDuration = const Duration(milliseconds: 350),
}) {
  hideLoading();
  child ??= _DefaultLoadingWidget(msg: text ?? "加载中...");
  _LoadingStateFul newChild = _LoadingStateFul(
    fadeDuration: fadeDuration,
    isClickDismiss: isClickDismiss,
    onDismiss: () {
      if(onClickDismiss != null){
        onClickDismiss();
      }
      hideLoading();
    },
    bgColor: bgColor,
    child: child,
  );
  _entry = OverlayEntry(builder: (context) {
    return newChild;
  });
  try {
    OverlayState overlay = Overlay.of(context);
    overlay.insert(_entry!);
  } catch (err) {
    hideLoading();
  }
}