showProgress static method

Future<void> showProgress(
  1. double value, {
  2. BuildContext? context,
  3. String? message,
  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,
  19. bool? isInteractive,
})

显示进度,值应在0.0-1.0之间。

Implementation

static Future<void> showProgress(
  double value, {
  BuildContext? context,
  String? message,
  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,
  bool? isInteractive,
}) async {
  assert(
    value >= 0.0 && value <= 1.0,
    'progress value should be 0.0 ~ 1.0',
  );

  final ToastThemeData theme =
      context == null ? _instance._theme : ToastTheme.of(context);
  final Color foreground = _foreground(theme, foregroundColor);
  final double effectiveIndicatorSize = _indicatorSize(theme, indicatorSize);
  final double effectiveIndicatorWidth =
      _indicatorWidth(theme, indicatorWidth);

  Widget indicator;
  if (_instance._container == null || _instance.progressKey == null) {
    if (_instance.key != null) {
      await dismiss(animation: false);
    }
    final GlobalKey<ToastProgressState> progressKey =
        GlobalKey<ToastProgressState>();
    final GlobalKey<MessageAndIndicatorState> messageKey =
        GlobalKey<MessageAndIndicatorState>();
    indicator = ToastProgress(
      key: progressKey,
      value: value,
      size: effectiveIndicatorSize,
      color: foreground,
      width: effectiveIndicatorWidth,
    );

    if (message != null) {
      indicator = MessageAndIndicator(
        key: messageKey,
        textStyle: textStyle,
        textAlign: textAlign,
        foregroundColor: foreground,
        message: message,
        indicator: indicator,
        verticalGap: verticalGap,
        visualDensity: visualDensity,
      );
    }

    _instance._show(
      theme,
      child: indicator,
      dismissOnTap: dismissOnTap,
      backgroundColor: backgroundColor,
      maskColor: maskColor,
      displayDuration: animationDuration,
      position: position,
      padding: padding,
      isInteractive: isInteractive,
      animationBuilder: animationBuilder,
      borderRadius: borderRadius,
    );
    _instance._messageKey = messageKey;
    _instance._progressKey = progressKey;
  } else {
    // 更新进度
    _instance.progressKey?.currentState?.updateProgress(math.min(1.0, value));
    // 更新消息
    _instance.messageKey?.currentState?.updateMessage(message);
  }
}