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 Color? onColor;
|
||||||
final String label;
|
final String label;
|
||||||
|
|
||||||
static Color contrastColor(Color color) {
|
static Color contrastColor(Color color) =>
|
||||||
final brightness = ThemeData.estimateBrightnessForColor(color);
|
switch (ThemeData.estimateBrightnessForColor(color)) {
|
||||||
switch (brightness) {
|
Brightness.dark => Colors.white,
|
||||||
case Brightness.dark:
|
Brightness.light => Colors.black
|
||||||
return Colors.white;
|
};
|
||||||
case Brightness.light:
|
|
||||||
return Colors.black;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|||||||
@@ -108,29 +108,26 @@ class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget createScreenFor(
|
Widget createScreenFor(
|
||||||
ScreenSelected screenSelected, bool showNavBarExample) {
|
ScreenSelected screenSelected,
|
||||||
switch (screenSelected) {
|
bool showNavBarExample,
|
||||||
case ScreenSelected.component:
|
) =>
|
||||||
return Expanded(
|
switch (screenSelected) {
|
||||||
child: OneTwoTransition(
|
ScreenSelected.component => Expanded(
|
||||||
animation: railAnimation,
|
child: OneTwoTransition(
|
||||||
one: FirstComponentList(
|
animation: railAnimation,
|
||||||
showNavBottomBar: showNavBarExample,
|
one: FirstComponentList(
|
||||||
|
showNavBottomBar: showNavBarExample,
|
||||||
|
scaffoldKey: scaffoldKey,
|
||||||
|
showSecondList: showMediumSizeLayout || showLargeSizeLayout),
|
||||||
|
two: SecondComponentList(
|
||||||
scaffoldKey: scaffoldKey,
|
scaffoldKey: scaffoldKey,
|
||||||
showSecondList: showMediumSizeLayout || showLargeSizeLayout),
|
),
|
||||||
two: SecondComponentList(
|
|
||||||
scaffoldKey: scaffoldKey,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
ScreenSelected.color => const ColorPalettesScreen(),
|
||||||
case ScreenSelected.color:
|
ScreenSelected.typography => const TypographyScreen(),
|
||||||
return const ColorPalettesScreen();
|
ScreenSelected.elevation => const ElevationScreen()
|
||||||
case ScreenSelected.typography:
|
};
|
||||||
return const TypographyScreen();
|
|
||||||
case ScreenSelected.elevation:
|
|
||||||
return const ElevationScreen();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PreferredSizeWidget createAppBar() {
|
PreferredSizeWidget createAppBar() {
|
||||||
return AppBar(
|
return AppBar(
|
||||||
|
|||||||
@@ -47,17 +47,13 @@ class _AppState extends State<App> {
|
|||||||
ColorScheme? imageColorScheme = const ColorScheme.light();
|
ColorScheme? imageColorScheme = const ColorScheme.light();
|
||||||
ColorSelectionMethod colorSelectionMethod = ColorSelectionMethod.colorSeed;
|
ColorSelectionMethod colorSelectionMethod = ColorSelectionMethod.colorSeed;
|
||||||
|
|
||||||
bool get useLightMode {
|
bool get useLightMode => switch (themeMode) {
|
||||||
switch (themeMode) {
|
ThemeMode.system =>
|
||||||
case ThemeMode.system:
|
View.of(context).platformDispatcher.platformBrightness ==
|
||||||
return View.of(context).platformDispatcher.platformBrightness ==
|
Brightness.light,
|
||||||
Brightness.light;
|
ThemeMode.light => true,
|
||||||
case ThemeMode.light:
|
ThemeMode.dark => false
|
||||||
return true;
|
};
|
||||||
case ThemeMode.dark:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void handleBrightnessChange(bool useLightMode) {
|
void handleBrightnessChange(bool useLightMode) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|||||||
Reference in New Issue
Block a user