From 59693b73757384999ccb5987570f37ed2683a1f9 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 31 Jul 2023 17:15:23 +0200 Subject: [PATCH] refactor: simplify UIA stage selection logic (Also prevents a potential out of bounds exception) --- lib/src/utils/uia_request.dart | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/src/utils/uia_request.dart b/lib/src/utils/uia_request.dart index e3a3b81f..7f1f0dff 100644 --- a/lib/src/utils/uia_request.dart +++ b/lib/src/utils/uia_request.dart @@ -102,17 +102,11 @@ class UiaRequest { List flows, List completed) { final nextStages = {}; for (final flow in flows) { - final stages = flow.stages; - final nextStage = stages[completed.length]; - var stagesValid = true; - for (var i = 0; i < completed.length; i++) { - if (stages[i] != completed[i]) { - stagesValid = false; - break; - } - } - if (stagesValid) { - nextStages.add(nextStage); + // check the flow starts with the completed stages + if (flow.stages.length >= completed.length && + flow.stages.take(completed.length).toSet().containsAll(completed)) { + final stages = flow.stages.skip(completed.length); + if (stages.isNotEmpty) nextStages.add(stages.first); } } return nextStages;