The key function is to avoid ambiguity. As in interpolation it is possible to use any valid expression in code in some situations it may be that the compiler does not know what to do and determine where the expression ended.
This is exactly what happened with the first case. He understood that the expression was only the word following the $
, the rest would be text, because it could be text itself, as the compiler will know? The point encloses a token And so what he finds afterwards is considered normal text, which is not what he wants. The keys work as parentheses there grouping all the expression and indicating pro compiler that all that is one thing and only after closing the key is that it comes back have normal text to be printed without an evaluation.
Pro compiler the first case is as if written "${widget}.nome"
. Some languages require you to always have the keys to avoid confusion, because it’s just like you always have, only in some situations Dart puts the keys to you where he thinks you should, not necessarily where you wanted. I would standardize putting keys always even where there is no ambiguity.
Contrary to what the other answer says, although this has to do with interpolation, it’s not the keys that interpolate, it’s just a disambiguation mechanism, if it was interpolation then the first case would not interpolate at all and it does, Only the wrong way you wanted it. It also has nothing to do with dice type.
who gave the downvote can explain the reason or is particular?
– Ricardo Pontual