download method Null safety

Future<bool> download()

Downloads data and stores it locally if possible.

Returns true if the downloaded string is different from the previously stored one. May throw an Exception.

Implementation

Future<bool> download() async {
  final Response response = await get(uri);
  if (response.statusCode != 200) {
    throw Exception('status is ${response.statusCode} for $uri');
  }
  _value = response.body;

  if (dao != null) {
    final String key = uri.toString();
    final String? previousString = await dao!.get(key);
    if (_value == previousString) {
      return false;
    }
    await dao!.put(key, _value);
  }
  return true;
}