ProgressModel class

A progress bar widget with optional animation support.

The progress bar can be rendered statically using viewAs or animated using the update loop and setPercent commands.

Example (Static)

// Simple static progress bar
final progress = ProgressModel(width: 40);
print(progress.viewAs(0.5)); // 50% complete

Example (Animated)

class DownloadModel implements Model {
  final ProgressModel progress;
  final double downloaded;

  DownloadModel({ProgressModel? progress, this.downloaded = 0})
      : progress = progress ?? ProgressModel();

  @override
  (Model, Cmd?) update(Msg msg) {
    // Handle progress animation frames
    final (newProgress, cmd) = progress.update(msg);
    if (newProgress != progress) {
      return (
        DownloadModel(progress: newProgress as ProgressModel, downloaded: downloaded),
        cmd,
      );
    }

    // Handle download progress updates
    if (msg is DownloadProgressMsg) {
      final newPercent = msg.bytes / msg.total;
      final (updatedProgress, animCmd) = progress.setPercent(newPercent);
      return (
        DownloadModel(progress: updatedProgress, downloaded: newPercent),
        animCmd,
      );
    }

    return (this, null);
  }

  @override
  String view() => progress.view();
}
Inheritance

Constructors

ProgressModel({int width = _defaultWidth, String full = defaultFullCharHalfBlock, String fullColor = '#7571F9', String empty = defaultEmptyCharBlock, String emptyColor = '#606060', bool showPercentage = true, String percentFormat = ' %3.0f%%', Style? percentageStyle, double frequency = _defaultFrequency, double damping = _defaultDamping, bool useGradient = false, String gradientColorA = '#5A56E0', String gradientColorB = '#EE6FF8', List<String> blend = const [], ColorFunc? colorFunc, bool scaleGradient = false, bool scaleBlend = false, bool indeterminate = false, double pulseWidth = 0.2, DateTime? startTime, DateTime nowProvider()?, double percentShown = 0, double targetPercent = 0, double velocity = 0, double pulseOffset = 0, int? id, int tag = 0})
Creates a new progress bar model.

Properties

blend → List<String>
Blend of colors to use. When provided, overrides fullColor and useGradient.
final
colorFunc → ColorFunc?
Function to dynamically color the progress bar. Overrides blend, fullColor, and useGradient.
final
damping → double
Spring damping (bounciness).
final
empty → String
Character for empty sections.
final
emptyColor → String
Color for empty sections.
final
eta → String
Returns the estimated time remaining as a string (MM:SS).
no setter
frequency → double
Spring frequency (speed).
final
full → String
Character for filled sections.
final
fullColor → String
Color for filled sections.
final
gradientColorA → String
First color of the gradient.
final
gradientColorB → String
Second color of the gradient.
final
hashCode → int
The hash code for this object.
no setterinherited
id → int
The progress bar's unique ID.
no setter
indeterminate → bool
Whether the progress bar is in indeterminate mode.
final
isAnimating → bool
Whether the progress bar is currently animating.
no setter
percent → double
The target percentage.
no setter
percentageStyle → Style
Style for the percentage text.
final
percentFormat → String
Format string for the percentage (e.g., " %3.0f%%").
final
percentShown → double
The current visible percentage (for animation).
no setter
pulseOffset → double
The current pulse offset (for indeterminate mode).
no setter
pulseWidth → double
Width of the pulse in indeterminate mode (as a fraction of total width).
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scaleBlend → bool
Whether to scale the blend to the filled portion.
final
scaleGradient → bool
Whether to scale the gradient to the filled portion.
final
showPercentage → bool
Whether to show the percentage text.
final
startTime → DateTime?
When the progress started (for ETA calculation).
final
tag → int
Current frame tag (exposed for testing/inspection).
no setter
useGradient → bool
Whether to use a gradient fill.
final
width → int
Total width of the progress bar, including percentage.
final

Methods

copyWith({int? width, String? full, String? fullColor, String? empty, String? emptyColor, bool? showPercentage, String? percentFormat, Style? percentageStyle, bool? useGradient, String? gradientColorA, String? gradientColorB, List<String>? blend, ColorFunc? colorFunc, bool? scaleGradient, bool? scaleBlend, bool? indeterminate, double? pulseWidth, DateTime? startTime, DateTime nowProvider()?, double? percentShown, double? targetPercent, double? velocity, double? pulseOffset, int? tag, double? frequency, double? damping}) → ProgressModel
Creates a copy with the given fields replaced.
decrPercent(double v) → (ProgressModel, Cmd?)
Decrements the percentage by the given amount.
incrPercent(double v) → (ProgressModel, Cmd?)
Increments the percentage by the given amount.
init() → Cmd?
Returns an optional command to execute on program startup.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setPercent(double p, {bool animate = true}) → (ProgressModel, Cmd?)
Sets the target percentage and returns a command for animation.
toString() → String
A string representation of this object.
inherited
update(Msg msg) → (ProgressModel, Cmd?)
Updates the component state in response to a message.
override
view() → String
Renders the current model state for display.
override
viewAs(double percent) → String
Renders the progress bar at the given percentage (static rendering).
withColorFunc(ColorFunc fn) → ProgressModel
Returns a copy of the model with the given color function.
withColors(List<String> colors) → ProgressModel
Returns a copy of the model with the given colors.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

withDefaultBlend({int width = _defaultWidth}) → ProgressModel
Creates a new progress bar with the default blend of colors (purple to pink).