Refactoring if chains into switch statements (#144905)
Based on issue #144903, this PR aims to bring the codebase more in line with the [Flutter repo style guide](https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#avoid-using-if-chains-or--or--with-enum-values): > #### Avoid using `if` chains or `?:` or `==` with enum values <br> This change unfortunately increases the total line length, but it also improves readability.
This commit is contained in:
@@ -40,14 +40,15 @@ class NavigationIconView {
|
||||
|
||||
FadeTransition transition(BottomNavigationBarType type, BuildContext context) {
|
||||
Color? iconColor;
|
||||
if (type == BottomNavigationBarType.shifting) {
|
||||
iconColor = _color;
|
||||
} else {
|
||||
final ThemeData theme = Theme.of(context);
|
||||
final ColorScheme colorScheme = theme.colorScheme;
|
||||
iconColor = theme.brightness == Brightness.light
|
||||
? colorScheme.primary
|
||||
: colorScheme.secondary;
|
||||
switch (type) {
|
||||
case BottomNavigationBarType.shifting:
|
||||
iconColor = _color;
|
||||
case BottomNavigationBarType.fixed:
|
||||
final ThemeData theme = Theme.of(context);
|
||||
iconColor = switch (theme.brightness) {
|
||||
Brightness.light => theme.colorScheme.primary,
|
||||
Brightness.dark => theme.colorScheme.secondary,
|
||||
};
|
||||
}
|
||||
|
||||
return FadeTransition(
|
||||
|
||||
@@ -37,13 +37,16 @@ class _MarkerPainter extends CustomPainter {
|
||||
..color = const Color(0xFFFFFFFF)
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1.0;
|
||||
if (type == MarkerType.topLeft) {
|
||||
canvas.drawLine(Offset(r, r), Offset(r + r - 1.0, r), paint);
|
||||
canvas.drawLine(Offset(r, r), Offset(r, r + r - 1.0), paint);
|
||||
}
|
||||
if (type == MarkerType.bottomRight) {
|
||||
canvas.drawLine(Offset(r, r), Offset(1.0, r), paint);
|
||||
canvas.drawLine(Offset(r, r), Offset(r, 1.0), paint);
|
||||
|
||||
switch (type) {
|
||||
case MarkerType.topLeft:
|
||||
canvas.drawLine(Offset(r, r), Offset(r + r - 1.0, r), paint);
|
||||
canvas.drawLine(Offset(r, r), Offset(r, r + r - 1.0), paint);
|
||||
case MarkerType.bottomRight:
|
||||
canvas.drawLine(Offset(r, r), Offset(1.0, r), paint);
|
||||
canvas.drawLine(Offset(r, r), Offset(r, 1.0), paint);
|
||||
case MarkerType.touch:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user