Skip to content

Commit 6c0e937

Browse files
committed
Add optional parameters to resetProgress() for initialization
- resetProgress() now accepts optional progress and statusMessage parameters - Allows initializing commands to specific values (e.g., resuming at 50%) - Without parameters, resets to defaults (0.0, null) - Updated documentation with examples
1 parent 304f3b5 commit 6c0e937

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
- Implementation uses wrapper functions in WithProgress factories to call `reset()` automatically
1010

1111
**New Methods**:
12-
- `Command.resetProgress()` - Manually reset progress state (useful for clearing 100% progress from UI)
12+
- `Command.resetProgress({double? progress, String? statusMessage})` - Manually reset/initialize progress state
13+
- Without parameters: resets to defaults (0.0, null)
14+
- With parameters: initializes to specific values (useful for resuming operations)
1315

1416
**Technical Details**:
1517
- Added `ProgressHandle.reset()` method to clear all state back to initial values

lib/command_it.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,19 +624,30 @@ abstract class Command<TParam, TResult> extends CustomValueNotifier<TResult> {
624624
/// Clears progress (to 0.0), statusMessage (to null), and isCanceled (to false).
625625
/// This is called automatically at the start of each execution, but can also
626626
/// be called manually when needed (e.g., to clear 100% progress from UI after
627-
/// completion).
627+
/// completion, or to initialize a command to a specific progress value).
628+
///
629+
/// Optional parameters allow setting specific initial values:
630+
/// - [progress]: Initial progress value (0.0-1.0), defaults to 0.0
631+
/// - [statusMessage]: Initial status message, defaults to null
628632
///
629633
/// Example:
630634
/// ```dart
631-
/// // After successful completion, reset progress for next run
635+
/// // Reset to default (0.0, null)
636+
/// command.resetProgress();
637+
///
638+
/// // Initialize to 50% with a message
639+
/// command.resetProgress(progress: 0.5, statusMessage: 'Resuming...');
640+
///
641+
/// // Clear 100% progress after completion
632642
/// if (command.progress.value == 1.0) {
633643
/// await Future.delayed(Duration(seconds: 2));
634644
/// command.resetProgress();
635645
/// }
636646
/// ```
637647
///
638648
/// For commands without progress (created with regular factories), this is a no-op.
639-
void resetProgress() => _handle?.reset();
649+
void resetProgress({double? progress, String? statusMessage}) =>
650+
_handle?.reset(progress: progress, statusMessage: statusMessage);
640651

641652
/// optional hander that will get called on any exception that happens inside
642653
/// any Command of the app. Ideal for logging.

lib/progress_handle.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,18 @@ class ProgressHandle {
9393
///
9494
/// Called automatically at the start of each command execution.
9595
/// Resets:
96-
/// - [progress] to 0.0
97-
/// - [statusMessage] to null
96+
/// - [progress] to 0.0 (or specified value)
97+
/// - [statusMessage] to null (or specified value)
9898
/// - [isCanceled] to false
9999
///
100+
/// Optional parameters allow initializing to specific values instead
101+
/// of defaults, useful for starting commands at a non-zero progress.
102+
///
100103
/// This ensures each command execution starts with clean state,
101104
/// especially important for the cancellation flag.
102-
void reset() {
103-
_progress.value = 0.0;
104-
_statusMessage.value = null;
105+
void reset({double? progress, String? statusMessage}) {
106+
_progress.value = progress ?? 0.0;
107+
_statusMessage.value = statusMessage;
105108
_isCanceled.value = false;
106109
}
107110

0 commit comments

Comments
 (0)