checkForUpdates static method
Check for updates from pub.dev Returns the latest version if available, null otherwise
Implementation
static Future<String?> checkForUpdates({bool forceCheck = false}) async {
try {
// Check cache first unless forced
if (!forceCheck) {
final cachedVersion = await _readCachedVersion();
if (cachedVersion != null) {
return cachedVersion;
}
}
// Query pub.dev API
final response = await dio.get(
pubDevApiUrl,
options: Options(
headers: {
'Accept': 'application/json',
},
receiveTimeout: const Duration(seconds: 5),
),
);
if (response.statusCode == 200) {
final data = response.data;
final latestVersion = data['latest']?['version'] as String?;
if (latestVersion != null) {
// Cache the result
await _writeCache(latestVersion);
return latestVersion;
}
}
return null;
} catch (e) {
// Silently fail - don't interrupt user's workflow
return null;
}
}