[material_3_demo] Use switch expressions (#2193)

pull/2194/head
Kevin Moore 4 months ago committed by GitHub
parent e5f3bacaf8
commit 5b6d214d2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -357,15 +357,11 @@ class ColorChip extends StatelessWidget {
final Color? onColor;
final String label;
static Color contrastColor(Color color) {
final brightness = ThemeData.estimateBrightnessForColor(color);
switch (brightness) {
case Brightness.dark:
return Colors.white;
case Brightness.light:
return Colors.black;
}
}
static Color contrastColor(Color color) =>
switch (ThemeData.estimateBrightnessForColor(color)) {
Brightness.dark => Colors.white,
Brightness.light => Colors.black
};
@override
Widget build(BuildContext context) {

@ -108,29 +108,26 @@ class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
}
Widget createScreenFor(
ScreenSelected screenSelected, bool showNavBarExample) {
switch (screenSelected) {
case ScreenSelected.component:
return Expanded(
child: OneTwoTransition(
animation: railAnimation,
one: FirstComponentList(
showNavBottomBar: showNavBarExample,
ScreenSelected screenSelected,
bool showNavBarExample,
) =>
switch (screenSelected) {
ScreenSelected.component => Expanded(
child: OneTwoTransition(
animation: railAnimation,
one: FirstComponentList(
showNavBottomBar: showNavBarExample,
scaffoldKey: scaffoldKey,
showSecondList: showMediumSizeLayout || showLargeSizeLayout),
two: SecondComponentList(
scaffoldKey: scaffoldKey,
showSecondList: showMediumSizeLayout || showLargeSizeLayout),
two: SecondComponentList(
scaffoldKey: scaffoldKey,
),
),
),
);
case ScreenSelected.color:
return const ColorPalettesScreen();
case ScreenSelected.typography:
return const TypographyScreen();
case ScreenSelected.elevation:
return const ElevationScreen();
}
}
ScreenSelected.color => const ColorPalettesScreen(),
ScreenSelected.typography => const TypographyScreen(),
ScreenSelected.elevation => const ElevationScreen()
};
PreferredSizeWidget createAppBar() {
return AppBar(

@ -47,17 +47,13 @@ class _AppState extends State<App> {
ColorScheme? imageColorScheme = const ColorScheme.light();
ColorSelectionMethod colorSelectionMethod = ColorSelectionMethod.colorSeed;
bool get useLightMode {
switch (themeMode) {
case ThemeMode.system:
return View.of(context).platformDispatcher.platformBrightness ==
Brightness.light;
case ThemeMode.light:
return true;
case ThemeMode.dark:
return false;
}
}
bool get useLightMode => switch (themeMode) {
ThemeMode.system =>
View.of(context).platformDispatcher.platformBrightness ==
Brightness.light,
ThemeMode.light => true,
ThemeMode.dark => false
};
void handleBrightnessChange(bool useLightMode) {
setState(() {

Loading…
Cancel
Save