isLottieFile method

bool isLottieFile(
  1. AssetType type
)

Implementation

bool isLottieFile(AssetType type) {
  if (type.mime != 'application/json') {
    return false;
  }
  try {
    final absolutePath = p.join(type.rootPath, type.path);
    String input = File(absolutePath).readAsStringSync();
    final fileKeys = jsonDecode(input) as Map<String, dynamic>;
    if (lottieKeys.every(fileKeys.containsKey) && fileKeys['v'] != null) {
      var version = Version.parse(fileKeys['v']);
      // Lottie version 4.4.0 is the first version that supports BodyMovin.
      // https://github.com/xvrh/lottie-flutter/blob/0e7499d82ea1370b6acf023af570395bbb59b42f/lib/src/parser/lottie_composition_parser.dart#L60
      return version >= Version(4, 4, 0);
    }
  } on FormatException catch (_) {
    // Catches bad/corrupted json and reports it to user.
    // stderr.writeln(e.message);
    // no-op
  } on TypeError catch (_) {
    // Catches bad/corrupted json and reports it to user.
    // stderr.writeln(e);
    // no-op
  }
  return false;
}