diff --git a/lib/flow_builder.dart b/lib/flow_builder.dart index 6cd6051..8a47f27 100644 --- a/lib/flow_builder.dart +++ b/lib/flow_builder.dart @@ -9,6 +9,13 @@ import 'package:flutter/widgets.dart'; /// and the current [List]. typedef OnGeneratePages = List Function(T, List); +/// Signature for function which given an input flow state [T] will +/// output a new flow state [T]. +/// +/// It is used to compute the next flow state with [FlowController.update] and +/// [FlowController.complete]. +typedef FlowCallback = T Function(T state); + /// {@template flow_builder} /// [FlowBuilder] abstracts navigation and exposes a declarative routing API /// based on a [state]. @@ -258,7 +265,7 @@ class FlowController implements Listenable { /// /// When [update] is called, the `builder` method of the corresponding /// [FlowBuilder] will be called with the new flow state. - void update(T Function(T) callback) { + void update(FlowCallback callback) { _notifier.value = callback(_notifier.value); } @@ -267,7 +274,7 @@ class FlowController implements Listenable { /// and is responsible for returning the new flow state. /// /// When [complete] is called, the flow is popped with the new flow state. - void complete([T Function(T)? callback]) { + void complete([FlowCallback? callback]) { _completed = true; final state = callback?.call(_notifier.value) ?? _notifier.value; if (state == _notifier.value) { @@ -322,12 +329,12 @@ class FakeFlowController extends FlowController { bool get completed => _completed; @override - void update(T Function(T) callback) { + void update(FlowCallback callback) { _state = callback(_state); } @override - void complete([T Function(T)? callback]) { + void complete([FlowCallback? callback]) { _completed = true; if (callback != null) { _state = callback(_state);