@@ -619,6 +619,25 @@ abstract class Command<TParam, TResult> extends CustomValueNotifier<TResult> {
619619 /// The function must check `handle.isCanceled.value` and decide how to handle it.
620620 void cancel () => _handle? .cancel ();
621621
622+ /// Manually resets all progress state to initial values.
623+ ///
624+ /// Clears progress (to 0.0), statusMessage (to null), and isCanceled (to false).
625+ /// This is called automatically at the start of each execution, but can also
626+ /// be called manually when needed (e.g., to clear 100% progress from UI after
627+ /// completion).
628+ ///
629+ /// Example:
630+ /// ```dart
631+ /// // After successful completion, reset progress for next run
632+ /// if (command.progress.value == 1.0) {
633+ /// await Future.delayed(Duration(seconds: 2));
634+ /// command.resetProgress();
635+ /// }
636+ /// ```
637+ ///
638+ /// For commands without progress (created with regular factories), this is a no-op.
639+ void resetProgress () => _handle? .reset ();
640+
622641 /// optional hander that will get called on any exception that happens inside
623642 /// any Command of the app. Ideal for logging.
624643 /// the [name] of the Command that was responsible for the error is inside
@@ -1877,8 +1896,11 @@ abstract class Command<TParam, TResult> extends CustomValueNotifier<TResult> {
18771896 // Create the ProgressHandle
18781897 final handle = ProgressHandle ();
18791898
1880- // Wrap the user's function to inject the handle
1881- Future <TResult > wrappedFunc (TParam param) => func (param, handle);
1899+ // Wrap the user's function to reset handle state and inject the handle
1900+ Future <TResult > wrappedFunc (TParam param) async {
1901+ handle.reset (); // Reset progress state before each execution
1902+ return await func (param, handle);
1903+ }
18821904
18831905 // Create the command with the wrapped function
18841906 final command = CommandAsync <TParam , TResult >(
@@ -1935,8 +1957,11 @@ abstract class Command<TParam, TResult> extends CustomValueNotifier<TResult> {
19351957 // Create the ProgressHandle
19361958 final handle = ProgressHandle ();
19371959
1938- // Wrap the user's function to inject the handle
1939- Future <TResult > wrappedFunc () => func (handle);
1960+ // Wrap the user's function to reset handle state and inject the handle
1961+ Future <TResult > wrappedFunc () async {
1962+ handle.reset (); // Reset progress state before each execution
1963+ return await func (handle);
1964+ }
19401965
19411966 // Create the command with the wrapped function
19421967 final command = CommandAsync <void , TResult >(
@@ -1987,8 +2012,11 @@ abstract class Command<TParam, TResult> extends CustomValueNotifier<TResult> {
19872012 // Create the ProgressHandle
19882013 final handle = ProgressHandle ();
19892014
1990- // Wrap the user's action to inject the handle
1991- Future <void > wrappedAction (TParam param) => action (param, handle);
2015+ // Wrap the user's action to reset handle state and inject the handle
2016+ Future <void > wrappedAction (TParam param) async {
2017+ handle.reset (); // Reset progress state before each execution
2018+ return await action (param, handle);
2019+ }
19922020
19932021 // Create the command with the wrapped action
19942022 final command = CommandAsync <TParam , void >(
@@ -2039,8 +2067,11 @@ abstract class Command<TParam, TResult> extends CustomValueNotifier<TResult> {
20392067 // Create the ProgressHandle
20402068 final handle = ProgressHandle ();
20412069
2042- // Wrap the user's action to inject the handle
2043- Future <void > wrappedAction () => action (handle);
2070+ // Wrap the user's action to reset handle state and inject the handle
2071+ Future <void > wrappedAction () async {
2072+ handle.reset (); // Reset progress state before each execution
2073+ return await action (handle);
2074+ }
20442075
20452076 // Create the command with the wrapped action
20462077 final command = CommandAsync <void , void >(
@@ -2113,10 +2144,12 @@ abstract class Command<TParam, TResult> extends CustomValueNotifier<TResult> {
21132144 // Create the ProgressHandle
21142145 final handle = ProgressHandle ();
21152146
2116- // Wrap the user's function to inject the handle
2147+ // Wrap the user's function to reset handle state and inject the handle
21172148 Future <TResult > wrappedFunc (
2118- TParam param, UndoStack <TUndoState > undoStack) =>
2119- func (param, handle, undoStack);
2149+ TParam param, UndoStack <TUndoState > undoStack) async {
2150+ handle.reset (); // Reset progress state before each execution
2151+ return await func (param, handle, undoStack);
2152+ }
21202153
21212154 // Create the command with the wrapped function
21222155 final command = UndoableCommand <TParam , TResult , TUndoState >(
@@ -2184,9 +2217,11 @@ abstract class Command<TParam, TResult> extends CustomValueNotifier<TResult> {
21842217 // Create the ProgressHandle
21852218 final handle = ProgressHandle ();
21862219
2187- // Wrap the user's function to inject the handle
2188- Future <TResult > wrappedFunc (UndoStack <TUndoState > undoStack) =>
2189- func (handle, undoStack);
2220+ // Wrap the user's function to reset handle state and inject the handle
2221+ Future <TResult > wrappedFunc (UndoStack <TUndoState > undoStack) async {
2222+ handle.reset (); // Reset progress state before each execution
2223+ return await func (handle, undoStack);
2224+ }
21902225
21912226 // Create the command with the wrapped function
21922227 final command = UndoableCommand <void , TResult , TUndoState >(
@@ -2248,9 +2283,12 @@ abstract class Command<TParam, TResult> extends CustomValueNotifier<TResult> {
22482283 // Create the ProgressHandle
22492284 final handle = ProgressHandle ();
22502285
2251- // Wrap the user's action to inject the handle
2252- Future <void > wrappedAction (TParam param, UndoStack <TUndoState > undoStack) =>
2253- action (param, handle, undoStack);
2286+ // Wrap the user's action to reset handle state and inject the handle
2287+ Future <void > wrappedAction (
2288+ TParam param, UndoStack <TUndoState > undoStack) async {
2289+ handle.reset (); // Reset progress state before each execution
2290+ return await action (param, handle, undoStack);
2291+ }
22542292
22552293 // Create the command with the wrapped action
22562294 final command = UndoableCommand <TParam , void , TUndoState >(
@@ -2313,9 +2351,11 @@ abstract class Command<TParam, TResult> extends CustomValueNotifier<TResult> {
23132351 // Create the ProgressHandle
23142352 final handle = ProgressHandle ();
23152353
2316- // Wrap the user's action to inject the handle
2317- Future <void > wrappedAction (UndoStack <TUndoState > undoStack) =>
2318- action (handle, undoStack);
2354+ // Wrap the user's action to reset handle state and inject the handle
2355+ Future <void > wrappedAction (UndoStack <TUndoState > undoStack) async {
2356+ handle.reset (); // Reset progress state before each execution
2357+ return await action (handle, undoStack);
2358+ }
23192359
23202360 // Create the command with the wrapped action
23212361 final command = UndoableCommand <void , void , TUndoState >(
0 commit comments