request method
Use to acquire data from network or the cached file.
Allowed method is one of GET, POST
.
If method is null, the default method is GET
.
If duration is null, the file will last forever, or will be reacquired while duration from file created to now is greater than duration specified in the param.
Implementation
Future<String> request(
String url, {
Map<String, dynamic>? body,
String? charset,
Duration? duration,
String? method,
bool reacquire = false,
}) async {
timeout ??= const Duration(seconds: 10);
final valid = await _valid(url, duration: duration);
if (!valid || reacquire) {
final data = await _request(
body: body,
charset: charset,
method: method,
url: url,
).timeout(timeout!);
await _cache(url, data);
return data;
} else {
final file = await _generate(url);
return file.readAsString();
}
}