getNextChainedDocuments method

List<Map<String, dynamic>> getNextChainedDocuments(
  1. String? completedDocumentKey, {
  2. List<String> excludedKeys = const [],
  3. int? completedFlowStep,
  4. String? completedSelectedOptionId,
})

Implementation

List<Map<String, dynamic>> getNextChainedDocuments(
  String? completedDocumentKey, {
  List<String> excludedKeys = const [],
  int? completedFlowStep,
  String? completedSelectedOptionId,
}) {
  if (completedDocumentKey == null || completedDocumentKey.isEmpty) {
    return const <Map<String, dynamic>>[];
  }

  return customDocuments.where((document) {
    if (!isChainedCustomDocument(document)) {
      return false;
    }

    final prevKey = document['previousDocumentKey'];
    if (prevKey is! String || prevKey.isEmpty) {
      return false;
    }

    if (!matchesPreviousDocumentKey(prevKey, completedDocumentKey, completedFlowStep)) {
      // allow trigger by previousStepTriggerOptionValues as alternative
      final prevOptions = document['previousStepTriggerOptionValues'] as List?;
      if (!matchesPreviousStepTriggerOptionValues(
          prevOptions, completedDocumentKey, completedSelectedOptionId)) {
        return false;
      }
    }

    final key = document['key'] as String?;
    if (key == null || key.isEmpty) {
      return false;
    }

    return !_completedDocumentKeys.contains(key) && !excludedKeys.contains(key);
  }).toList(growable: false);
}