Skip to content

Proposal to implement pattern matching throughout the repo #150942

@nate-thegrate

Description

@nate-thegrate

It's fun to turn switch statements into switch expressions, but there are other interesting ways that pattern-matching can make things more concise & readable.

example (widget_inspector.dart):

// before
final Object? object = toObject(id);
if (object is Element) {
  final RenderObject? renderObject = object.renderObject;
  if (renderObject is RenderFlex) {
    renderObject.mainAxisAlignment = mainAxisAlignment;
  }
}


// after
if (toObject(id) case Element(:final RenderFlex renderObject)) {
  renderObject.mainAxisAlignment = mainAxisAlignment;
}

Metadata

Metadata

Assignees

Labels

P3Issues that are less important to the Flutter projectc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.r: solvedIssue is closed as solvedrefactorImproving readability/efficiency without behavioral changesteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions