DataSourceCallback typedef
DataSourceCallback =
Future Function({dynamic body, Map<String, String> ? headers, required String method, required String url})
Callback for fetching data from external sources (APIs, databases, etc.)
This allows the package user to implement their own data fetching logic for DataSource components without forcing a specific HTTP client dependency.
Parameters:
url: The URL or endpoint to fetch data frommethod: HTTP method (GET, POST, etc.)headers: Optional map of headers to include in the requestbody: Optional request body for POST/PUT requests
Returns:
- A Future that resolves to the fetched data (typically Map or List)
Example implementation:
Future<dynamic> myDataFetcher({
required String url,
required String method,
Map<String, String>? headers,
dynamic body,
}) async {
final response = await http.get(Uri.parse(url), headers: headers);
if (response.statusCode == 200) {
return json.decode(response.body);
}
throw Exception('Failed to fetch data');
}
Implementation
typedef DataSourceCallback = Future<dynamic> Function({
required String url,
required String method,
Map<String, String>? headers,
dynamic body,
});