Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code readability on some functions #851

Open
TheLiux opened this issue Sep 12, 2023 · 0 comments
Open

Improve code readability on some functions #851

TheLiux opened this issue Sep 12, 2023 · 0 comments
Assignees
Labels
refactoring only code changes, not the result/look theme

Comments

@TheLiux
Copy link
Contributor

TheLiux commented Sep 12, 2023

Hi!
While I was checking the code, I noticed some functions with nested if that caught my attention.

Example:

Color _getSwitchThumbColor(Set<MaterialState> states, ColorScheme colorScheme) {
  if (states.contains(MaterialState.disabled)) {
    if (states.contains(MaterialState.selected)) {
      return colorScheme.onSurface.withOpacity(0.5);
    }
    return colorScheme.onSurface.withOpacity(0.5);
  } else {
    return colorScheme.onPrimary;
  }
}

Honestly, if is not necessary, I find nested if like this confusing when i read the code.
I think a better approach like this with early returns is better than the current:

Color _getSwitchThumbColor(Set<MaterialState> states, ColorScheme colorScheme) {
  if (states.contains(MaterialState.disabled)) {
    return colorScheme.onSurface.withOpacity(0.5);
  }

  return colorScheme.onPrimary;
}
@Feichtmeier Feichtmeier transferred this issue from ubuntu/archive_yaru.dart Feb 25, 2024
@Feichtmeier Feichtmeier added the refactoring only code changes, not the result/look label Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring only code changes, not the result/look theme
Projects
None yet
Development

No branches or pull requests

2 participants