You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if we could control how the content in a file is converted to a dart object by giving a variable annotated with @EmbedLiteral a concrete type like Map<String, int>.
For example, suppose there is a JSON file such as:
Then we should be able to control how the above JSON object is converted into a Dart object by declaring the variable with a type:
// main.dart@EmbedLiteral("./data.json")
// This variable should be a Map literalconstMap<String, int> dataAsMap = _$dataAsMap;
EmbedLiteral("./data.json")
// This variable should be a record literalconst ({ int apple, int banana, int orange }) dataAsRecord = _$dataAsRecord;
Even better, this pattern matching allows you to partially extract data from the content file by specifying a desired structure of the record literal to be generated.
// another_main.dart@EmbedLiteral("./data.json")
// takes only the `apple` and `banana` data from `data.jsonconst ({ int apple, int banana }) partialData = _$partialData;
These features are useful to ensure that the generated objects always have the same structure, or in cases where the content is huge but only a portion of it is of interest.
The text was updated successfully, but these errors were encountered:
It would be nice if we could control how the content in a file is converted to a dart object by giving a variable annotated with
@EmbedLiteral
a concrete type likeMap<String, int>
.For example, suppose there is a JSON file such as:
Then we should be able to control how the above JSON object is converted into a Dart object by declaring the variable with a type:
The generated code will look like this:
Even better, this pattern matching allows you to partially extract data from the content file by specifying a desired structure of the record literal to be generated.
This will generate the source:
These features are useful to ensure that the generated objects always have the same structure, or in cases where the content is huge but only a portion of it is of interest.
The text was updated successfully, but these errors were encountered: