fetchData static method
Fetches data for a DataSource component.
fetchConfig is the 'fetch' configuration map from the component definition.
formData is the current form data for interpolation.
Implementation
static Future<dynamic> fetchData({
required Map<String, dynamic> fetchConfig,
required Map<String, dynamic> formData,
}) async {
final url = fetchConfig['url']?.toString();
if (url == null || url.isEmpty) {
throw 'No URL specified';
}
final method = fetchConfig['method']?.toString() ?? 'get';
final headers = _buildHeaders(fetchConfig['headers'], formData);
// Make HTTP request
final dio = Dio();
final response = await dio.request(
url,
options: Options(method: method.toUpperCase(), headers: headers),
);
// Transform data using mapFunction
final mapFunction = fetchConfig['mapFunction']?.toString();
return _transformData(response.data, mapFunction);
}