getLatestVersion method

Future<String?> getLatestVersion()

Fetches the latest version of flo_cli from pub.dev. Returns the latest version string, or null if the check fails.

Implementation

Future<String?> getLatestVersion() async {
  try {
    final client = HttpClient();
    final request = await client
        .getUrl(Uri.parse('https://pub.dev/api/packages/flo_cli'));
    final response = await request.close();

    if (response.statusCode == 200) {
      final responseBody = await response.transform(utf8.decoder).join();
      final json = jsonDecode(responseBody);
      return json['latest']['version'] as String;
    }
  } catch (_) {
    // Ignore network errors during update check
  }
  return null;
}