loading static method
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,
显示加载状态
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);
}
}