fetchForms method

Future<List<FormModel>> fetchForms()

Fetches all available forms from the Form.io backend.

Makes a GET /form request.

Returns a list of FormModel objects.

Throws DioError on failure.

Implementation

Future<List<FormModel>> fetchForms() async {
  try {
    final response = await client.dio.get('/form');
    if (response.data is List<dynamic>) {
      final data = response.data as List<dynamic>;
      return data.map((json) => FormModel.fromJson(json as Map<String, dynamic>)).toList();
    }

    // handle response
  } on DioException catch (e) {
    print('DioException occurred:');
    print('Type: ${e.type}');
    print('Message: ${e.message}');
    print('Request: ${e.requestOptions.method} ${e.requestOptions.uri}');
    if (e.response != null) {
      print('Status code: ${e.response?.statusCode}');
      print('Data: ${e.response?.data}');
      print('Headers: ${e.response?.headers}');
    } else {
      print('Underlying error: ${e.error}');
    }
  } catch (e) {
    print('Other exception: $e');
  }
  throw 'Failed to fetch forms';

}