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
162.17k stars 26.65k forks source link

`flutter/lib/src/`: refactoring if-chains into switch expressions #147472

Closed nate-thegrate closed 1 week ago

nate-thegrate commented 2 weeks ago

Based on issue #144903, this pull request aims to bring the codebase more in line with the Flutter repo style guide:

Avoid using if chains or ?: or == with enum values


// before
bool get shown {
  if (overlayEntry == null) {
    return false;
  }
  if (animationController != null) {
    return animationController!.status == AnimationStatus.completed ||
        animationController!.status == AnimationStatus.forward;
  }
  return true;
}

// after
bool get shown {
  return overlayEntry != null && switch (animationController?.status) {
    AnimationStatus.forward || AnimationStatus.completed || null => true,
    AnimationStatus.reverse || AnimationStatus.dismissed => false,
  };
}

This pull request is similar to a previous PR with the same name but has a bit more thorough refactoring overall.

nate-thegrate commented 1 week ago

@nate-thegrate Are you interested in getting contributor access by the way? I'd be happy to sponsor you.

@justinmc That would be awesome, thank you very much!