startFlow method
Future<void>
startFlow(
- F flowType,
- S initialStep,
- Map<String, dynamic> pFlowState, {
- bool? endPreviousFlow = true,
})
Implementation
Future<void> startFlow(
F flowType,
S initialStep,
Map<String, dynamic> pFlowState, {
bool? endPreviousFlow = true,
}) async {
__.in_('startFlow');
try {
checkInitialized('FlowManager');
// If another flow is active, end it first
if (_activeFlow != null &&
_activeFlow!.flowType != flowType &&
endPreviousFlow == true) {
__.info(
'Ending previous flow: ${_activeFlow!.flowType} before starting: $flowType',
);
endFlow(_activeFlow!.flowType);
}
final flow = _flowRegistry[flowType];
if (flow == null) {
throw Exception('No flow registered for type: $flowType');
}
flow.updateState(pFlowState);
_activeFlow = flow;
await flow.start(initialStep);
__.info('Started flow: $flowType at step: ${initialStep.toString()}');
} catch (e, stackTrace) {
final wrapped = hujFlowException(
message: 'Failed to start flow: $flowType',
hujType: hujErrorType.flow,
originalError: e,
);
__.severe(wrapped.message, wrapped, stackTrace);
throw wrapped;
} finally {
__.out_('startFlow');
}
}