Closed maryx closed 6 years ago
@maryx:
It seems like the Dart Analyzer can't determine whether the child of a
<Widget>[]
isnew
orconst
, so we have to manually specifynew
. E.g. for this code:
This feature was reverted. There is no such thing as "automatic const" anymore, only "optional new". Once you specify the context as const
once, then the remaining constructor calls are implicitly const. Consider:
class Animal {
const Animal();
}
void main() {
// Same as "final animals = [new Animal()]"
final animals = [Animal()];
// Same as "const animals = const [const Animal()]"
const animals = [Animal()]
}
In your case children:
is not a const context.
re: prefer_const_literals_to_create_immutables
You might want to also file this as dart-lang/linter
, as it isn't part of the SDK proper:
https://github.com/dart-lang/linter/issues
Ah thanks, I hadn't been sure where to file this - redirecting and closing this.
dart --version
didn't work butflutter --version
givesTools • Dart 2.0.0-dev.48.0.flutter-fe606f890b
Linux
It seems like the Dart Analyzer can't determine whether the child of a
<Widget>[]
isnew
orconst
, so we have to manually specifynew
. E.g. for this code:If I omit the
new
for the third child, I geterror • Prefer const literals as parameters of constructors on @immutable classes at package:... • prefer_const_literals_to_create_immutables
and a green squiggle under the word<Widget>
in VS Code.Is this expected?