getLocalAppVersion method

Future<String?> getLocalAppVersion()

Implementation

Future<String?> getLocalAppVersion() async {
  try {
    // Read the pubspec.yaml file
    final file = File('pubspec.yaml');
    final content = await file.readAsString();

    // Parse the YAML content
    final yamlMap = loadYaml(content);

    // Extract the version field
    final version = yamlMap['version'];

    return version?.toString();
  } catch (e) {
    debugPrint('Error reading pubspec.yaml: $e');

    return null;
  }
}