getMetadata static method

Future<Map<String, dynamic>?> getMetadata(
  1. String filePath
)

Extracts the metadata of a file without loading the whole template

Implementation

static Future<Map<String, dynamic>?> getMetadata(String filePath) async {
  try {
    final file = File(filePath);
    if (!await file.exists()) return null;

    final content = await file.readAsString(encoding: utf8);
    final json = jsonDecode(content) as Map<String, dynamic>;

    if (json['format'] != 'rpt') return null;

    return Map<String, dynamic>.from(json['metadata'] ?? {});
  } catch (_) {
    return null;
  }
}