getText method
Fetches plain text (UTF-8 string) from a Uri.
Supports file, http, and https schemes. Throws UnsupportedError
for any unsupported scheme.
Implementation
Future<String> getText(
Uri uri, {
Duration? ttl,
bool forceRefresh = false,
}) async {
switch (uri.scheme.toLowerCase()) {
case 'file':
return File.fromUri(uri).readAsString();
case 'http':
case 'https':
final file = await getFile(
uri.toString(),
ttl: ttl,
forceRefresh: forceRefresh,
);
if (file == null) {
throw HttpException('Failed to load remote text from $uri', uri: uri);
}
return file.readAsString();
default:
throw UnsupportedError('Unsupported URI scheme: ${uri.scheme}');
}
}