fetchAndStoreChangelog method
Fetch the changelog from GitHub and store it in cache file. This runs in the background and does not block the UI.
Implementation
Future<void> fetchAndStoreChangelog() async {
if (isNonInteractive) return;
if (isEssentialTrafficOnly) return;
try {
String? content;
if (_httpGet != null) {
content = await _httpGet(_rawChangelogUrl);
} else {
final client = HttpClient();
try {
final request = await client.getUrl(Uri.parse(_rawChangelogUrl));
final response = await request.close();
if (response.statusCode == 200) {
content = await response.transform(utf8.decoder).join();
}
} finally {
client.close();
}
}
if (content == null) return;
// Skip write if content unchanged
if (content == changelogCache.value) return;
final cachePath = _changelogCachePath;
final cacheDir = Directory(
cachePath.substring(0, cachePath.lastIndexOf('/')),
);
if (!cacheDir.existsSync()) {
cacheDir.createSync(recursive: true);
}
await File(cachePath).writeAsString(content);
changelogCache.value = content;
} catch (_) {
// Silently fail -- this is a background operation
}
}