mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
[material_3_demo] Use switch expressions (#2193)
This commit is contained in:
@@ -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(() {
|
||||
|
||||
Reference in New Issue
Block a user