flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.03k stars 27.42k forks source link

Proposal: factor out `Geometry` class declarations #157890

Open nate-thegrate opened 2 hours ago

nate-thegrate commented 2 hours ago

Assumption

This issue assumes that Dart will have a convenient dot syntax in the somewhat near future:

Padding(
  padding: .only(left: 42.0),
)


Problem

Both EdgeInsets and EdgeInsetsDirectional have a .only() constructor; there would need to be a way to differentiate between the two.


Proposal

Change the class structure.

Before

abstract class EdgeInsetsGeometry {}

class EdgeInsets extends EdgeInsetsGeometry {}

class EdgeInsetsDirectional extends EdgeInsetsGeometry {}

After

@Deprecated()
typedef EdgeInsetsGeometry = EdgeInsets;

class EdgeInsets {}

class EdgeInsetsDirectional extends EdgeInsets {}

And then .only() would hopefully be interpreted as EdgeInsets.only() by default. (The same would be done with AlignmentGeometry and BorderRadiusGeometry as well.)


I believe this should be a mostly trivial/non-breaking transition, with one catch:

void foo(EdgeInsetsDirectional directionalPadding) {
  print(directionalPadding is EdgeInsets); // would change from "false" to "true"
}
nate-thegrate commented 2 hours ago

(forgot I need to unassign for this to show up in triage 😄)