Skip to content

Proposal: use "enhanced enums" in the repo for reduced boilerplate #147799

@nate-thegrate

Description

@nate-thegrate

There are a few situations where the same enum logic is implemented over and over again.


A good example would be distinguishing an AnimationStatus between forward/complete and reverse/dismissed.

15 style guide violations (click to collapse)

return status == AnimationStatus.completed || status == AnimationStatus.forward;

return status == AnimationStatus.completed || status == AnimationStatus.forward;

return status == AnimationStatus.completed || status == AnimationStatus.forward;

final bool isOpen = status == AnimationStatus.completed || status == AnimationStatus.forward;

return _controller.status == AnimationStatus.completed ||
_controller.status == AnimationStatus.forward;

return status == AnimationStatus.completed ||
status == AnimationStatus.forward;

if (status == AnimationStatus.completed ||
status == AnimationStatus.forward) {

return status == AnimationStatus.completed ||
status == AnimationStatus.forward;

return status == AnimationStatus.completed ||
status == AnimationStatus.forward;

return animation.status == AnimationStatus.forward
|| animation.status == AnimationStatus.completed;

return animation.status == AnimationStatus.forward || animation.status == AnimationStatus.completed;

_snackBarController!.status == AnimationStatus.forward ||
_snackBarController!.status == AnimationStatus.completed,

widget.animationController.status == AnimationStatus.forward
|| widget.animationController.status == AnimationStatus.completed,

final bool transitioningForwards = _controller.status == AnimationStatus.completed ||
_controller.status == AnimationStatus.forward;

ignoring: animation!.status == AnimationStatus.reverse || // changedInternalState is called when animation.status updates
animation!.status == AnimationStatus.dismissed, // dismissed is possible when doing a manual pop gesture

Rather than refactoring all of these into switch expressions, I think it'd be best to take advantage of enhanced enum features and improve AnimationStatus directly.

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