findDeclaredType method
DartType?
findDeclaredType()
Implementation
DartType? findDeclaredType() {
final varDecl = thisOrAncestorOfType<VariableDeclaration>();
if (varDecl != null) {
return switch (varDecl.parent) {
VariableDeclarationList(type: NamedType(:final type)) => type,
_ => null,
};
}
final returnType = thisOrAncestorOfType<FunctionDeclaration>()?.returnType;
if (returnType != null) {
return returnType.type;
}
final getterReturnType =
thisOrAncestorOfType<MethodDeclaration>()?.returnType;
if (getterReturnType != null) {
return getterReturnType.type;
}
return null;
}