loading static method

Future<void> loading({
  1. BuildContext? context,
  2. String? message,
  3. Widget? indicator,
  4. TextStyle? textStyle,
  5. Color? backgroundColor,
  6. Color? foregroundColor,
  7. EdgeInsetsGeometry? padding,
  8. BorderRadius? borderRadius,
  9. VisualDensity? visualDensity,
  10. TextAlign? textAlign,
  11. Color? maskColor,
  12. double? verticalGap,
  13. double? indicatorSize,
  14. double? indicatorWidth,
  15. ToastPosition? position,
  16. Duration? animationDuration,
  17. ToastAnimationBuilder? animationBuilder,
  18. bool? dismissOnTap = true,
  19. bool? isInteractive = false,
  20. bool updateOnly = true,
})

显示加载状态

updateOnly 只更新,值为true时,如果当前Toast已为loading状态,则只更新message 内容,不会重新弹出。

Implementation

/// 显示加载状态
///
/// [updateOnly] 只更新,值为true时,如果当前Toast已为loading状态,则只更新[message]
/// 内容,不会重新弹出。
static Future<void> loading({
  BuildContext? context,
  String? message,
  Widget? indicator,
  TextStyle? textStyle,
  Color? backgroundColor,
  Color? foregroundColor,
  EdgeInsetsGeometry? padding,
  BorderRadius? borderRadius,
  VisualDensity? visualDensity,
  TextAlign? textAlign,
  Color? maskColor,
  double? verticalGap,
  double? indicatorSize,
  double? indicatorWidth,
  ToastPosition? position,
  Duration? animationDuration,
  ToastAnimationBuilder? animationBuilder,
  bool? dismissOnTap = true,
  bool? isInteractive = false,
  bool updateOnly = true,
}) async {
  final ToastThemeData theme =
      context == null ? _instance._theme : ToastTheme.of(context);
  final Color foreground = _foreground(theme, foregroundColor);
  Widget? effectiveIndicator = _indicator(theme, indicator);
  if (effectiveIndicator == null) {
    final double size = _indicatorSize(theme, indicatorSize);
    final double width = _indicatorWidth(theme, indicatorWidth);
    effectiveIndicator = ConstrainedBox(
      constraints: BoxConstraints(maxWidth: size, maxHeight: size),
      child: CircularProgressIndicator(strokeWidth: width, color: foreground),
    );
  }

  if (!updateOnly) {
    return await _instance._show(
      theme,
      dismissOnTap: dismissOnTap,
      child: effectiveIndicator,
      backgroundColor: backgroundColor,
      maskColor: maskColor,
      animationDuration: animationDuration,
      position: position,
      padding: padding,
      isInteractive: isInteractive,
      animationBuilder: animationBuilder,
      borderRadius: borderRadius,
    );
  }

  if (instance._loadingMessageKey == null) {
    final GlobalKey<MessageAndIndicatorState> loadingKey =
        GlobalKey<MessageAndIndicatorState>();
    effectiveIndicator = MessageAndIndicator(
      message: message,
      indicator: effectiveIndicator,
      key: loadingKey,
      foregroundColor: foreground,
      textAlign: textAlign,
      textStyle: textStyle,
      verticalGap: verticalGap,
      visualDensity: visualDensity,
    );
    instance._loadingMessageKey = loadingKey;
    return _instance._show(
      theme,
      dismissOnTap: dismissOnTap,
      child: effectiveIndicator,
      backgroundColor: backgroundColor,
      maskColor: maskColor,
      animationDuration: animationDuration,
      position: position,
      padding: padding,
      isInteractive: isInteractive,
      animationBuilder: animationBuilder,
      borderRadius: borderRadius,
    );
  } else {
    // 更新消息
    _instance.loadingMessageKey?.currentState?.updateMessage(message);
  }
}