getClassFromFile method Null safety

ClassDeclaration? getClassFromFile(
  1. String className,
  2. Uri fileUri
)

Implementation

ClassDeclaration? getClassFromFile(String className, Uri fileUri) {
  try {
    return _getFileAstRoot(fileUri)
        .declarations
        .whereType<ClassDeclaration>()
        .firstWhere((c) => c.name.value() == className);
  } catch (e) {
    if (e is StateError || e is TypeError || e is ArgumentError) {
      return null;
    }
    rethrow;
  }
}