Closed aloisdeniel closed 5 years ago
I can't do much about it. It's a blocker on the generator side
You may can check what is the first token in the sequence... but since computedNode is deprecated it is not a long term solution infortunately.
That computeNode
usage do not aim at being a long-term solution, so I'm fine with a deprecated function that barely fixes the problem.
It just handles the most common usage.
A potential solution could be to check if the node is an AnnotatedNode and if so, use visitChildren
to find the declared identifier.
How so? We're using computeNode
when the analyzer is unable to resolve nodes.
Hum, only when the element's type is undefined, not the element itself.
Reference _parameterToReference(ParameterElement element) {
if (element.type.isUndefined) {
return refer(element.computeNode().beginToken.toString());
}
We may here try to get the annotation associated with element
before accessing its first token.
I will try some experiments as soon as I get the time to.
Closing this, since I cannot do anything.
As a workaround you may use a custom object:
class MyColor {
MyColor(this.color);
final Color color;
}
and send it to the generator:
@widget Widget foo({@required MyColor color}) {}
This will correctly build.
When using a parameter both
@required
and with a type not included in the Dart SDK (Color
for example), the generation fails.Example :
Produces :
This is due of the access of the first token of the
computedNode
.