fetchQuestions method

Future<List?> fetchQuestions(
  1. int typeId,
  2. int? jobId, {
  3. bool forceRefresh = false,
})

Implementation

Future<List<dynamic>?> fetchQuestions(int typeId, int? jobId,
    {bool forceRefresh = false}) async {
  if (questionGroups == null || forceRefresh) {
    try {
      // Fetch the Form object
      DynamicFormModel? fetchedForm =
          await _dynamicFormService.fetchDynamicByTypeId(typeId);

      if (fetchedForm != null &&
          fetchedForm.items.isNotEmpty &&
          jobId != null) {
        _lastFetchedForms[jobId] = fetchedForm;
        questionGroups = fetchedForm.items;
        notifyListeners();
      } else {
        print("No form or questions received from the service");
      }
      return questionGroups;
    } catch (e) {
      print('Error fetching questions: $e');
      return null;
    }
  }
  return questionGroups;
}