Open jacob314 opened 4 years ago
You can also +1 dart-lang/sdk#32174 :)
This might be unfortunate in the case where the Rect could have been const, but operators won't allow that.
For example:
const Rect rect = Rect.fromLTWH(offset.dx, offset.dy, size.dx, size.dy);
Is valid if offset
and size
are const, but
const Rect rect = offset & size;
Is not valid.
I can't reproduce that case.
const Offset offset = Offset(3.0, 4.0);
const Size size = Size(4.0, 5.0);
const Rect rect = Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height);
Fails with the error: "error: Arguments of a constant creation must be constant expressions. (const_with_non_constant_argument at...."
Yeah, I edited it to fix - you have to use the .dx
and .dy
properties, since width and height are getters.
Do you mean ._dx
and .dy
for size?
._dx
and ._dy
are private on the size object so I'm not clear how those can be used unless your code is in package:flutter
Ahh ok - I guess this is impossible then. I don't know why I thought I had done it.
This lint is for users of the Flutter framework to help them discover that the
&
operator often provides a cleaner way to define rectangles..Examples
Should generate a lint hint that you should write
instead.
Additional context It is hard for users to discover that the
&
operator is often the right way to create aRect
instance. Autocomplete in Dart doesn't suggest operators and for autocomplete to ever help in this case, users would need to know to start with the offset. What we want is some way to suggest a lint or autocomplete style hint whenever a user creates a Rectangle that could be more easily created with&
that they should.