Skip to content

Proposal to implement null-aware operators (?. and ??) throughout the repo #143803

@nate-thegrate

Description

@nate-thegrate

Most of the Flutter codebase takes full advantage of null-aware operators, but I found a few spots here and there that could be improved.

// before
if (query != null) {
  return query._data;
}
return null;

// after
return query?.data;
// before
if (box != null) {
  return box.size.width;
}
return _kWidth;

// after
return box?.size.width ?? _kWidth;
// before
if (visual != null) {
  return visual;
}
if (logical != null) {
  return logical;
}
return 'BorderRadius.zero';

// after
return visual ?? logical ?? 'BorderRadius.zero';

Metadata

Metadata

Assignees

No one assigned

    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.refactorImproving 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