Unverified Commit 223f8ed6 authored by Pierre-Louis's avatar Pierre-Louis Committed by GitHub

Reland "Refactor ThemeData (#91497)" (part 2) (#92970)

parent 58409c19
...@@ -362,10 +362,32 @@ class ThemeData with Diagnosticable { ...@@ -362,10 +362,32 @@ class ThemeData with Diagnosticable {
) )
bool? fixTextFieldOutlineLabel, bool? fixTextFieldOutlineLabel,
}) { }) {
// GENERAL CONFIGURATION
applyElevationOverlayColor ??= false;
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
inputDecorationTheme ??= const InputDecorationTheme();
platform ??= defaultTargetPlatform;
switch (platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
materialTapTargetSize ??= MaterialTapTargetSize.padded;
break;
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
materialTapTargetSize ??= MaterialTapTargetSize.shrinkWrap;
break;
}
pageTransitionsTheme ??= const PageTransitionsTheme();
scrollbarTheme ??= const ScrollbarThemeData();
splashFactory ??= InkSplash.splashFactory;
visualDensity ??= VisualDensity.adaptivePlatformDensity;
// COLOR
assert(colorScheme?.brightness == null || brightness == null || colorScheme!.brightness == brightness); assert(colorScheme?.brightness == null || brightness == null || colorScheme!.brightness == brightness);
final Brightness _brightness = brightness ?? colorScheme?.brightness ?? Brightness.light; final Brightness _brightness = brightness ?? colorScheme?.brightness ?? Brightness.light;
final bool isDark = _brightness == Brightness.dark; final bool isDark = _brightness == Brightness.dark;
visualDensity ??= VisualDensity.adaptivePlatformDensity;
primarySwatch ??= Colors.blue; primarySwatch ??= Colors.blue;
primaryColor ??= isDark ? Colors.grey[900]! : primarySwatch; primaryColor ??= isDark ? Colors.grey[900]! : primarySwatch;
primaryColorBrightness ??= estimateBrightnessForColor(primaryColor); primaryColorBrightness ??= estimateBrightnessForColor(primaryColor);
...@@ -376,13 +398,14 @@ class ThemeData with Diagnosticable { ...@@ -376,13 +398,14 @@ class ThemeData with Diagnosticable {
accentColor ??= isDark ? Colors.tealAccent[200]! : primarySwatch[500]!; accentColor ??= isDark ? Colors.tealAccent[200]! : primarySwatch[500]!;
accentColorBrightness ??= estimateBrightnessForColor(accentColor); accentColorBrightness ??= estimateBrightnessForColor(accentColor);
final bool accentIsDark = accentColorBrightness == Brightness.dark; final bool accentIsDark = accentColorBrightness == Brightness.dark;
canvasColor ??= isDark ? Colors.grey[850]! : Colors.grey[50]!; focusColor ??= isDark ? Colors.white.withOpacity(0.12) : Colors.black.withOpacity(0.12);
hoverColor ??= isDark ? Colors.white.withOpacity(0.04) : Colors.black.withOpacity(0.04);
shadowColor ??= Colors.black; shadowColor ??= Colors.black;
canvasColor ??= isDark ? Colors.grey[850]! : Colors.grey[50]!;
scaffoldBackgroundColor ??= canvasColor; scaffoldBackgroundColor ??= canvasColor;
bottomAppBarColor ??= isDark ? Colors.grey[800]! : Colors.white; bottomAppBarColor ??= isDark ? Colors.grey[800]! : Colors.white;
cardColor ??= isDark ? Colors.grey[800]! : Colors.white; cardColor ??= isDark ? Colors.grey[800]! : Colors.white;
dividerColor ??= isDark ? const Color(0x1FFFFFFF) : const Color(0x1F000000); dividerColor ??= isDark ? const Color(0x1FFFFFFF) : const Color(0x1F000000);
// Create a ColorScheme that is backwards compatible as possible // Create a ColorScheme that is backwards compatible as possible
// with the existing default ThemeData color values. // with the existing default ThemeData color values.
colorScheme ??= ColorScheme.fromSwatch( colorScheme ??= ColorScheme.fromSwatch(
...@@ -394,60 +417,21 @@ class ThemeData with Diagnosticable { ...@@ -394,60 +417,21 @@ class ThemeData with Diagnosticable {
errorColor: errorColor, errorColor: errorColor,
brightness: _brightness, brightness: _brightness,
); );
splashFactory ??= InkSplash.splashFactory;
selectedRowColor ??= Colors.grey[100]!; selectedRowColor ??= Colors.grey[100]!;
unselectedWidgetColor ??= isDark ? Colors.white70 : Colors.black54; unselectedWidgetColor ??= isDark ? Colors.white70 : Colors.black54;
// Spec doesn't specify a dark theme secondaryHeaderColor, this is a guess. // Spec doesn't specify a dark theme secondaryHeaderColor, this is a guess.
secondaryHeaderColor ??= isDark ? Colors.grey[700]! : primarySwatch[50]!; secondaryHeaderColor ??= isDark ? Colors.grey[700]! : primarySwatch[50]!;
textSelectionColor ??= isDark ? accentColor : primarySwatch[200]!;
cursorColor = cursorColor ?? const Color.fromRGBO(66, 133, 244, 1.0);
textSelectionHandleColor ??= isDark ? Colors.tealAccent[400]! : primarySwatch[300]!;
backgroundColor ??= isDark ? Colors.grey[700]! : primarySwatch[200]!; backgroundColor ??= isDark ? Colors.grey[700]! : primarySwatch[200]!;
dialogBackgroundColor ??= isDark ? Colors.grey[800]! : Colors.white; dialogBackgroundColor ??= isDark ? Colors.grey[800]! : Colors.white;
indicatorColor ??= accentColor == primaryColor ? Colors.white : accentColor; indicatorColor ??= accentColor == primaryColor ? Colors.white : accentColor;
hintColor ??= isDark ? Colors.white60 : Colors.black.withOpacity(0.6); hintColor ??= isDark ? Colors.white60 : Colors.black.withOpacity(0.6);
errorColor ??= Colors.red[700]!; errorColor ??= Colors.red[700]!;
inputDecorationTheme ??= const InputDecorationTheme(); // The default [buttonTheme] is here because it doesn't use the defaults for
pageTransitionsTheme ??= const PageTransitionsTheme(); // [disabledColor], [highlightColor], and [splashColor].
primaryIconTheme ??= primaryIsDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black);
accentIconTheme ??= accentIsDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black);
iconTheme ??= isDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black87);
platform ??= defaultTargetPlatform;
typography ??= Typography.material2014(platform: platform);
TextTheme defaultTextTheme = isDark ? typography.white : typography.black;
TextTheme defaultPrimaryTextTheme = primaryIsDark ? typography.white : typography.black;
TextTheme defaultAccentTextTheme = accentIsDark ? typography.white : typography.black;
if (fontFamily != null) {
defaultTextTheme = defaultTextTheme.apply(fontFamily: fontFamily);
defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(fontFamily: fontFamily);
defaultAccentTextTheme = defaultAccentTextTheme.apply(fontFamily: fontFamily);
}
textTheme = defaultTextTheme.merge(textTheme);
primaryTextTheme = defaultPrimaryTextTheme.merge(primaryTextTheme);
accentTextTheme = defaultAccentTextTheme.merge(accentTextTheme);
switch (platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
materialTapTargetSize ??= MaterialTapTargetSize.padded;
break;
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
materialTapTargetSize ??= MaterialTapTargetSize.shrinkWrap;
break;
}
applyElevationOverlayColor ??= false;
// Used as the default color (fill color) for RaisedButtons. Computing the
// default for ButtonThemeData for the sake of backwards compatibility.
buttonColor ??= isDark ? primarySwatch[600]! : Colors.grey[300]!;
focusColor ??= isDark ? Colors.white.withOpacity(0.12) : Colors.black.withOpacity(0.12);
hoverColor ??= isDark ? Colors.white.withOpacity(0.04) : Colors.black.withOpacity(0.04);
buttonTheme ??= ButtonThemeData( buttonTheme ??= ButtonThemeData(
colorScheme: colorScheme, colorScheme: colorScheme,
buttonColor: buttonColor, // Defaults to the fill color for RaisedButtons for backwards compatibility.
buttonColor: buttonColor ?? (isDark ? primarySwatch[600]! : Colors.grey[300]!),
disabledColor: disabledColor, disabledColor: disabledColor,
focusColor: focusColor, focusColor: focusColor,
hoverColor: hoverColor, hoverColor: hoverColor,
...@@ -455,50 +439,71 @@ class ThemeData with Diagnosticable { ...@@ -455,50 +439,71 @@ class ThemeData with Diagnosticable {
splashColor: splashColor, splashColor: splashColor,
materialTapTargetSize: materialTapTargetSize, materialTapTargetSize: materialTapTargetSize,
); );
toggleButtonsTheme ??= const ToggleButtonsThemeData();
disabledColor ??= isDark ? Colors.white38 : Colors.black38; disabledColor ??= isDark ? Colors.white38 : Colors.black38;
highlightColor ??= isDark ? _kDarkThemeHighlightColor : _kLightThemeHighlightColor; highlightColor ??= isDark ? _kDarkThemeHighlightColor : _kLightThemeHighlightColor;
splashColor ??= isDark ? _kDarkThemeSplashColor : _kLightThemeSplashColor; splashColor ??= isDark ? _kDarkThemeSplashColor : _kLightThemeSplashColor;
sliderTheme ??= const SliderThemeData(); // TYPOGRAPHY & ICONOGRAPHY
tabBarTheme ??= const TabBarTheme(); typography ??= Typography.material2014(platform: platform);
tooltipTheme ??= const TooltipThemeData(); TextTheme defaultTextTheme = isDark ? typography.white : typography.black;
TextTheme defaultPrimaryTextTheme = primaryIsDark ? typography.white : typography.black;
TextTheme defaultAccentTextTheme = accentIsDark ? typography.white : typography.black;
if (fontFamily != null) {
defaultTextTheme = defaultTextTheme.apply(fontFamily: fontFamily);
defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(fontFamily: fontFamily);
defaultAccentTextTheme = defaultAccentTextTheme.apply(fontFamily: fontFamily);
}
textTheme = defaultTextTheme.merge(textTheme);
primaryTextTheme = defaultPrimaryTextTheme.merge(primaryTextTheme);
iconTheme ??= isDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black87);
primaryIconTheme ??= primaryIsDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black);
// COMPONENT THEMES
appBarTheme ??= const AppBarTheme(); appBarTheme ??= const AppBarTheme();
scrollbarTheme ??= const ScrollbarThemeData(); bannerTheme ??= const MaterialBannerThemeData();
bottomAppBarTheme ??= const BottomAppBarTheme(); bottomAppBarTheme ??= const BottomAppBarTheme();
bottomNavigationBarTheme ??= const BottomNavigationBarThemeData();
bottomSheetTheme ??= const BottomSheetThemeData();
buttonBarTheme ??= const ButtonBarThemeData();
cardTheme ??= const CardTheme(); cardTheme ??= const CardTheme();
chipTheme ??= ChipThemeData.fromDefaults( chipTheme ??= ChipThemeData.fromDefaults(
secondaryColor: isDark ? Colors.tealAccent[200]! : primaryColor, secondaryColor: isDark ? Colors.tealAccent[200]! : primaryColor,
brightness: colorScheme.brightness, brightness: colorScheme.brightness,
labelStyle: textTheme.bodyText1!, labelStyle: textTheme.bodyText1!,
); );
checkboxTheme ??= const CheckboxThemeData();
dataTableTheme ??= const DataTableThemeData();
dialogTheme ??= const DialogTheme(); dialogTheme ??= const DialogTheme();
dividerTheme ??= const DividerThemeData();
drawerTheme ??= const DrawerThemeData();
elevatedButtonTheme ??= const ElevatedButtonThemeData();
floatingActionButtonTheme ??= const FloatingActionButtonThemeData(); floatingActionButtonTheme ??= const FloatingActionButtonThemeData();
listTileTheme ??= const ListTileThemeData();
navigationBarTheme ??= const NavigationBarThemeData(); navigationBarTheme ??= const NavigationBarThemeData();
navigationRailTheme ??= const NavigationRailThemeData(); navigationRailTheme ??= const NavigationRailThemeData();
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
snackBarTheme ??= const SnackBarThemeData();
bottomSheetTheme ??= const BottomSheetThemeData();
popupMenuTheme ??= const PopupMenuThemeData();
bannerTheme ??= const MaterialBannerThemeData();
dividerTheme ??= const DividerThemeData();
buttonBarTheme ??= const ButtonBarThemeData();
bottomNavigationBarTheme ??= const BottomNavigationBarThemeData();
timePickerTheme ??= const TimePickerThemeData();
textButtonTheme ??= const TextButtonThemeData();
elevatedButtonTheme ??= const ElevatedButtonThemeData();
outlinedButtonTheme ??= const OutlinedButtonThemeData(); outlinedButtonTheme ??= const OutlinedButtonThemeData();
textSelectionTheme ??= const TextSelectionThemeData(); popupMenuTheme ??= const PopupMenuThemeData();
dataTableTheme ??= const DataTableThemeData(); progressIndicatorTheme ??= const ProgressIndicatorThemeData();
checkboxTheme ??= const CheckboxThemeData();
radioTheme ??= const RadioThemeData(); radioTheme ??= const RadioThemeData();
sliderTheme ??= const SliderThemeData();
snackBarTheme ??= const SnackBarThemeData();
switchTheme ??= const SwitchThemeData(); switchTheme ??= const SwitchThemeData();
progressIndicatorTheme ??= const ProgressIndicatorThemeData(); tabBarTheme ??= const TabBarTheme();
drawerTheme ??= const DrawerThemeData(); textButtonTheme ??= const TextButtonThemeData();
listTileTheme ??= const ListTileThemeData(); textSelectionTheme ??= const TextSelectionThemeData();
timePickerTheme ??= const TimePickerThemeData();
toggleButtonsTheme ??= const ToggleButtonsThemeData();
tooltipTheme ??= const TooltipThemeData();
fixTextFieldOutlineLabel ??= true; // DEPRECATED (newest deprecations at the bottom)
useTextSelectionTheme ??= true; useTextSelectionTheme ??= true;
textSelectionColor ??= isDark ? accentColor : primarySwatch[200]!;
cursorColor = cursorColor ?? const Color.fromRGBO(66, 133, 244, 1.0);
textSelectionHandleColor ??= isDark ? Colors.tealAccent[400]! : primarySwatch[300]!;
accentTextTheme = defaultAccentTextTheme.merge(accentTextTheme);
accentIconTheme ??= accentIsDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black);
buttonColor ??= isDark ? primarySwatch[600]! : Colors.grey[300]!;
fixTextFieldOutlineLabel ??= true;
return ThemeData.raw( return ThemeData.raw(
// GENERAL CONFIGURATION // GENERAL CONFIGURATION
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment