switch statement cleanup (#148382)
This PR is step 12 in the journey to solve issue #136139 and make the entire Flutter repo more readable. Most of it involves implementing switch expressions, and there's also a few other random things that I wanted to clean up a bit.
This commit is contained in:
@@ -50,15 +50,11 @@ enum GalleryDemoCategory {
|
||||
}
|
||||
|
||||
String? displayTitle(GalleryLocalizations localizations) {
|
||||
switch (this) {
|
||||
case GalleryDemoCategory.other:
|
||||
return localizations.homeCategoryReference;
|
||||
case GalleryDemoCategory.material:
|
||||
case GalleryDemoCategory.cupertino:
|
||||
return toString();
|
||||
case GalleryDemoCategory.study:
|
||||
}
|
||||
return null;
|
||||
return switch (this) {
|
||||
study => null,
|
||||
material || cupertino => toString(),
|
||||
other => localizations.homeCategoryReference,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,22 +96,15 @@ class GalleryOptions {
|
||||
/// In other words, if the theme is dark, returns light; if the theme is
|
||||
/// light, returns dark.
|
||||
SystemUiOverlayStyle resolvedSystemUiOverlayStyle() {
|
||||
Brightness brightness;
|
||||
switch (themeMode) {
|
||||
case ThemeMode.light:
|
||||
brightness = Brightness.light;
|
||||
case ThemeMode.dark:
|
||||
brightness = Brightness.dark;
|
||||
case ThemeMode.system:
|
||||
brightness =
|
||||
WidgetsBinding.instance.platformDispatcher.platformBrightness;
|
||||
}
|
||||
|
||||
final SystemUiOverlayStyle overlayStyle = brightness == Brightness.dark
|
||||
? SystemUiOverlayStyle.light
|
||||
: SystemUiOverlayStyle.dark;
|
||||
|
||||
return overlayStyle;
|
||||
final Brightness brightness = switch (themeMode) {
|
||||
ThemeMode.light => Brightness.light,
|
||||
ThemeMode.dark => Brightness.dark,
|
||||
ThemeMode.system => WidgetsBinding.instance.platformDispatcher.platformBrightness,
|
||||
};
|
||||
return switch (brightness) {
|
||||
Brightness.light => SystemUiOverlayStyle.dark,
|
||||
Brightness.dark => SystemUiOverlayStyle.light,
|
||||
};
|
||||
}
|
||||
|
||||
GalleryOptions copyWith({
|
||||
|
||||
Reference in New Issue
Block a user