How can I get the type of an initial value expression of a field using Dart's analyzer API?
class MyClass {
var prop = <initial value expression>;
}
If initial value expression is for example 'text'
, I'd like to get String
. If it is a function call, I'd like to get the return type of the function.
After getting a fully resolved AST structure, ask the Expression
representing the initial value expression for it's staticType
. That will return the DartType
representing the static type.
It's possible for type inference to produce a more specialized type, which you can access using propagatedType
. (And if you don't care which type you get, you can use bestType
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With