refactor: estrai showUpdateDialog e parseTagName in file dedicati
Sposta la logica del dialog in lib/shared/widgets/update_dialog.dart per renderla importabile nei test senza duplicare il codice. Estrae parseTagName come metodo @visibleForTesting in UpdateService isolando il parsing JSON dalla chiamata HTTP. app.dart semplificato di conseguenza. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -27,14 +27,24 @@ class UpdateService {
|
||||
final body = await response.transform(utf8.decoder).join();
|
||||
client.close();
|
||||
if (response.statusCode != 200) return null;
|
||||
final data = jsonDecode(body) as Map<String, dynamic>;
|
||||
final tag = (data['tag_name'] as String).replaceFirst(RegExp(r'^v'), '');
|
||||
final tag = parseTagName(body);
|
||||
if (tag == null) return null;
|
||||
return isNewer(tag, kAppVersion) ? tag : null;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
static String? parseTagName(String body) {
|
||||
try {
|
||||
final data = jsonDecode(body) as Map<String, dynamic>;
|
||||
return (data['tag_name'] as String).replaceFirst(RegExp(r'^v'), '');
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
static bool isNewer(String remote, String local) {
|
||||
final r = parseVersion(remote);
|
||||
|
||||
Reference in New Issue
Block a user