-
Notifications
You must be signed in to change notification settings - Fork 228
Open
Labels
featureProposed language feature that solves one or more problemsProposed language feature that solves one or more problems
Description
Summary
Introduce a shorthand for object destructuring where the type name can be omitted when it can be inferred from the right-hand side, using a leading dot (.).
Motivation
Object destructuring currently requires repeating the type name even when the matched expression already provides it, leading to unnecessary verbosity:
final Point(:x, :y) = Point(1, 2);Proposal
Allow using a dot-prefixed object pattern whose type is inferred from the value being matched:
final .(:x, :y) = Point(1, 2);This behaves the same as explicitly writing Point(:x, :y) but without repeating the type.
Examples
// current
final Size(:width, :height) = size;
// proposed
final .(:width, :height) = size;// current
LayoutBuilder(
builder: (context, constraints) {
final BoxConstraints(:maxWidth, :maxHeight) = constraints;
// ...
},
);
// proposed
LayoutBuilder(
builder: (context, constraints) {
final .(:maxWidth, :maxHeight) = constraints;
// ...
},
);// current
GestureDetector(
onPanUpdate: (details) {
final DragUpdateDetails(delta: Offset(:dx, :dy)) = details;
// ...
},
);
// proposed
GestureDetector(
onPanUpdate: (details) {
final .(delta: .(:dx, :dy)) = details;
// ...
},
);PiotrRogulski, tenhobi, FMorschel and MiniSuperDevalbertms10
Metadata
Metadata
Assignees
Labels
featureProposed language feature that solves one or more problemsProposed language feature that solves one or more problems