Can I access metadata annotations of a type or parameter in flutter?

Viewed 1279

Or is that capability lost with the loss of the reflect package?

What I'm curious about is can I use annotations in my own flutter app? Or is that a feature only available in dart, but not flutter?

2 Answers

Annotations can only be used for static analysis in Flutter.

For example the analyzer that generates hints and warnings in your IDE, code generation tools like built_value, built_redux, json_serializable, and other packages that use https://github.com/dart-lang/build make use of this.

There is no way to get metadata information at runtime without dart:mirrors.

There is work in progress to make the reflectable package work with code generation. This might work with Flutter eventually to generate code that allows to access predefined metadata at runtime. See also https://github.com/dart-lang/reflectable/tree/use_build

Yes, of course you can use metadata annotations in flutter. Flutter has a meta-library, which you can look into to know about available annotations that can be used with flutter.

Hope this helped!

Related