Unverified Commit ac745b3f authored by Darren Austin's avatar Darren Austin Committed by GitHub

ThemeData property cleanup. (#91774)

parent acab6dcc
......@@ -1726,8 +1726,8 @@ class ThemeData with Diagnosticable {
unselectedWidgetColor: Color.lerp(a.unselectedWidgetColor, b.unselectedWidgetColor, t)!,
disabledColor: Color.lerp(a.disabledColor, b.disabledColor, t)!,
buttonTheme: t < 0.5 ? a.buttonTheme : b.buttonTheme,
toggleButtonsTheme: ToggleButtonsThemeData.lerp(a.toggleButtonsTheme, b.toggleButtonsTheme, t)!,
buttonColor: Color.lerp(a.buttonColor, b.buttonColor, t)!,
toggleButtonsTheme: ToggleButtonsThemeData.lerp(a.toggleButtonsTheme, b.toggleButtonsTheme, t)!,
secondaryHeaderColor: Color.lerp(a.secondaryHeaderColor, b.secondaryHeaderColor, t)!,
textSelectionColor: Color.lerp(a.textSelectionColor, b.textSelectionColor, t)!,
cursorColor: Color.lerp(a.cursorColor, b.cursorColor, t)!,
......@@ -1775,7 +1775,7 @@ class ThemeData with Diagnosticable {
textButtonTheme: TextButtonThemeData.lerp(a.textButtonTheme, b.textButtonTheme, t)!,
elevatedButtonTheme: ElevatedButtonThemeData.lerp(a.elevatedButtonTheme, b.elevatedButtonTheme, t)!,
outlinedButtonTheme: OutlinedButtonThemeData.lerp(a.outlinedButtonTheme, b.outlinedButtonTheme, t)!,
textSelectionTheme: TextSelectionThemeData .lerp(a.textSelectionTheme, b.textSelectionTheme, t)!,
textSelectionTheme: TextSelectionThemeData.lerp(a.textSelectionTheme, b.textSelectionTheme, t)!,
dataTableTheme: DataTableThemeData.lerp(a.dataTableTheme, b.dataTableTheme, t),
checkboxTheme: CheckboxThemeData.lerp(a.checkboxTheme, b.checkboxTheme, t),
radioTheme: RadioThemeData.lerp(a.radioTheme, b.radioTheme, t),
......@@ -1802,14 +1802,16 @@ class ThemeData with Diagnosticable {
&& other.primaryColorBrightness == primaryColorBrightness
&& other.primaryColorLight == primaryColorLight
&& other.primaryColorDark == primaryColorDark
&& other.canvasColor == canvasColor
&& other.shadowColor == shadowColor
&& other.accentColor == accentColor
&& other.accentColorBrightness == accentColorBrightness
&& other.canvasColor == canvasColor
&& other.scaffoldBackgroundColor == scaffoldBackgroundColor
&& other.bottomAppBarColor == bottomAppBarColor
&& other.cardColor == cardColor
&& other.shadowColor == shadowColor
&& other.dividerColor == dividerColor
&& other.focusColor == focusColor
&& other.hoverColor == hoverColor
&& other.highlightColor == highlightColor
&& other.splashColor == splashColor
&& other.splashFactory == splashFactory
......@@ -1890,10 +1892,10 @@ class ThemeData with Diagnosticable {
primaryColorBrightness,
primaryColorLight,
primaryColorDark,
accentColor,
accentColorBrightness,
canvasColor,
shadowColor,
accentColor,
accentColorBrightness,
scaffoldBackgroundColor,
bottomAppBarColor,
cardColor,
......@@ -1909,7 +1911,6 @@ class ThemeData with Diagnosticable {
buttonTheme,
buttonColor,
toggleButtonsTheme,
toggleableActiveColor,
secondaryHeaderColor,
textSelectionColor,
cursorColor,
......@@ -1919,6 +1920,7 @@ class ThemeData with Diagnosticable {
indicatorColor,
hintColor,
errorColor,
toggleableActiveColor,
textTheme,
primaryTextTheme,
accentTextTheme,
......@@ -1975,10 +1977,12 @@ class ThemeData with Diagnosticable {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
final ThemeData defaultData = ThemeData.fallback();
properties.add(DiagnosticsProperty<VisualDensity>('visualDensity', visualDensity, level: DiagnosticLevel.debug));
properties.add(EnumProperty<TargetPlatform>('platform', platform, defaultValue: defaultTargetPlatform, level: DiagnosticLevel.debug));
properties.add(EnumProperty<Brightness>('brightness', brightness, defaultValue: defaultData.brightness, level: DiagnosticLevel.debug));
properties.add(ColorProperty('primaryColor', primaryColor, defaultValue: defaultData.primaryColor, level: DiagnosticLevel.debug));
properties.add(EnumProperty<Brightness>('primaryColorBrightness', primaryColorBrightness, defaultValue: defaultData.primaryColorBrightness, level: DiagnosticLevel.debug));
properties.add(ColorProperty('primaryColorLight', primaryColorLight, defaultValue: defaultData.primaryColorLight, level: DiagnosticLevel.debug));
properties.add(ColorProperty('primaryColorDark', primaryColorDark, defaultValue: defaultData.primaryColorDark, level: DiagnosticLevel.debug));
properties.add(ColorProperty('accentColor', accentColor, defaultValue: defaultData.accentColor, level: DiagnosticLevel.debug));
properties.add(EnumProperty<Brightness>('accentColorBrightness', accentColorBrightness, defaultValue: defaultData.accentColorBrightness, level: DiagnosticLevel.debug));
properties.add(ColorProperty('canvasColor', canvasColor, defaultValue: defaultData.canvasColor, level: DiagnosticLevel.debug));
......@@ -1991,6 +1995,7 @@ class ThemeData with Diagnosticable {
properties.add(ColorProperty('hoverColor', hoverColor, defaultValue: defaultData.hoverColor, level: DiagnosticLevel.debug));
properties.add(ColorProperty('highlightColor', highlightColor, defaultValue: defaultData.highlightColor, level: DiagnosticLevel.debug));
properties.add(ColorProperty('splashColor', splashColor, defaultValue: defaultData.splashColor, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<InteractiveInkFeatureFactory>('splashFactory', splashFactory, defaultValue: defaultData.splashFactory, level: DiagnosticLevel.debug));
properties.add(ColorProperty('selectedRowColor', selectedRowColor, defaultValue: defaultData.selectedRowColor, level: DiagnosticLevel.debug));
properties.add(ColorProperty('unselectedWidgetColor', unselectedWidgetColor, defaultValue: defaultData.unselectedWidgetColor, level: DiagnosticLevel.debug));
properties.add(ColorProperty('disabledColor', disabledColor, defaultValue: defaultData.disabledColor, level: DiagnosticLevel.debug));
......@@ -2023,13 +2028,13 @@ class ThemeData with Diagnosticable {
properties.add(DiagnosticsProperty<bool>('applyElevationOverlayColor', applyElevationOverlayColor, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<PageTransitionsTheme>('pageTransitionsTheme', pageTransitionsTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<AppBarTheme>('appBarTheme', appBarTheme, defaultValue: defaultData.appBarTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<ScrollbarThemeData>('ScrollbarTheme', scrollbarTheme, defaultValue: defaultData.scrollbarTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<ScrollbarThemeData>('scrollbarTheme', scrollbarTheme, defaultValue: defaultData.scrollbarTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<BottomAppBarTheme>('bottomAppBarTheme', bottomAppBarTheme, defaultValue: defaultData.bottomAppBarTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<ColorScheme>('colorScheme', colorScheme, defaultValue: defaultData.colorScheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<DialogTheme>('dialogTheme', dialogTheme, defaultValue: defaultData.dialogTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<FloatingActionButtonThemeData>('floatingActionButtonThemeData', floatingActionButtonTheme, defaultValue: defaultData.floatingActionButtonTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<FloatingActionButtonThemeData>('floatingActionButtonTheme', floatingActionButtonTheme, defaultValue: defaultData.floatingActionButtonTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<NavigationBarThemeData>('navigationBarTheme', navigationBarTheme, defaultValue: defaultData.navigationBarTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<NavigationRailThemeData>('navigationRailThemeData', navigationRailTheme, defaultValue: defaultData.navigationRailTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<NavigationRailThemeData>('navigationRailTheme', navigationRailTheme, defaultValue: defaultData.navigationRailTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<Typography>('typography', typography, defaultValue: defaultData.typography, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<NoDefaultCupertinoThemeData>('cupertinoOverrideTheme', cupertinoOverrideTheme, defaultValue: defaultData.cupertinoOverrideTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<SnackBarThemeData>('snackBarTheme', snackBarTheme, defaultValue: defaultData.snackBarTheme, level: DiagnosticLevel.debug));
......@@ -2040,7 +2045,6 @@ class ThemeData with Diagnosticable {
properties.add(DiagnosticsProperty<ButtonBarThemeData>('buttonBarTheme', buttonBarTheme, defaultValue: defaultData.buttonBarTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<TimePickerThemeData>('timePickerTheme', timePickerTheme, defaultValue: defaultData.timePickerTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<TextSelectionThemeData>('textSelectionTheme', textSelectionTheme, defaultValue: defaultData.textSelectionTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<TextSelectionThemeData>('textSelectionTheme', textSelectionTheme, defaultValue: defaultData.textSelectionTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<BottomNavigationBarThemeData>('bottomNavigationBarTheme', bottomNavigationBarTheme, defaultValue: defaultData.bottomNavigationBarTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<TextButtonThemeData>('textButtonTheme', textButtonTheme, defaultValue: defaultData.textButtonTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<ElevatedButtonThemeData>('elevatedButtonTheme', elevatedButtonTheme, defaultValue: defaultData.elevatedButtonTheme, level: DiagnosticLevel.debug));
......@@ -2052,6 +2056,8 @@ class ThemeData with Diagnosticable {
properties.add(DiagnosticsProperty<ProgressIndicatorThemeData>('progressIndicatorTheme', progressIndicatorTheme, defaultValue: defaultData.progressIndicatorTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<DrawerThemeData>('drawerTheme', drawerTheme, defaultValue: defaultData.drawerTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<ListTileThemeData>('listTileTheme', listTileTheme, defaultValue: defaultData.listTileTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<bool>('fixTextFieldOutlineLabel', fixTextFieldOutlineLabel, defaultValue: true, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<bool>('useTextSelectionTheme', useTextSelectionTheme, defaultValue: true, level: DiagnosticLevel.debug));
properties.add(EnumProperty<AndroidOverscrollIndicator>('androidOverscrollIndicator', androidOverscrollIndicator, defaultValue: null, level: DiagnosticLevel.debug));
}
}
......
......@@ -245,8 +245,30 @@ void main() {
expect(expanded.maxHeight, equals(double.infinity));
});
testWidgets('ThemeData.copyWith correctly creates new ThemeData with all copied arguments', (WidgetTester tester) async {
test('copyWith, ==, hashCode basics', () {
expect(ThemeData(), ThemeData().copyWith());
expect(ThemeData().hashCode, ThemeData().copyWith().hashCode);
});
test('== and hashCode include focusColor and hoverColor', () {
// regression test for https://github.com/flutter/flutter/issues/91587
// Focus color and hover color are used in the default button theme, so
// use an empty one to ensure that just focus and hover colors are tested.
const ButtonThemeData buttonTheme = ButtonThemeData();
final ThemeData focusColorBlack = ThemeData(focusColor: Colors.black, buttonTheme: buttonTheme);
final ThemeData focusColorWhite = ThemeData(focusColor: Colors.white, buttonTheme: buttonTheme);
expect(focusColorBlack != focusColorWhite, true);
expect(focusColorBlack.hashCode != focusColorWhite.hashCode, true);
final ThemeData hoverColorBlack = ThemeData(hoverColor: Colors.black, buttonTheme: buttonTheme);
final ThemeData hoverColorWhite = ThemeData(hoverColor: Colors.white, buttonTheme: buttonTheme);
expect(hoverColorBlack != hoverColorWhite, true);
expect(hoverColorBlack.hashCode != hoverColorWhite.hashCode, true);
});
testWidgets('ThemeData.copyWith correctly creates new ThemeData with all copied arguments', (WidgetTester tester) async {
final SliderThemeData sliderTheme = SliderThemeData.fromPrimaryColors(
primaryColor: Colors.black,
primaryColorDark: Colors.black,
......@@ -640,4 +662,106 @@ void main() {
expect(theme.errorColor, equals(lightColors.error));
expect(theme.applyElevationOverlayColor, isFalse);
});
test('ThemeData diagnostics include all properties', () {
// List of properties must match the properties in ThemeData.hashCode()
final Set<String> expectedPropertyNames = <String>{
'visualDensity',
'primaryColor',
'primaryColorBrightness',
'primaryColorLight',
'primaryColorDark',
'canvasColor',
'shadowColor',
'accentColor',
'accentColorBrightness',
'scaffoldBackgroundColor',
'bottomAppBarColor',
'cardColor',
'dividerColor',
'focusColor',
'hoverColor',
'highlightColor',
'splashColor',
'splashFactory',
'selectedRowColor',
'unselectedWidgetColor',
'disabledColor',
'buttonTheme',
'buttonColor',
'toggleButtonsTheme',
'secondaryHeaderColor',
'textSelectionColor',
'cursorColor',
'textSelectionHandleColor',
'backgroundColor',
'dialogBackgroundColor',
'indicatorColor',
'hintColor',
'errorColor',
'toggleableActiveColor',
'textTheme',
'primaryTextTheme',
'accentTextTheme',
'inputDecorationTheme',
'iconTheme',
'primaryIconTheme',
'accentIconTheme',
'sliderTheme',
'tabBarTheme',
'tooltipTheme',
'cardTheme',
'chipTheme',
'platform',
'materialTapTargetSize',
'applyElevationOverlayColor',
'pageTransitionsTheme',
'appBarTheme',
'scrollbarTheme',
'bottomAppBarTheme',
'colorScheme',
'dialogTheme',
'floatingActionButtonTheme',
'navigationBarTheme',
'navigationRailTheme',
'typography',
'cupertinoOverrideTheme',
'snackBarTheme',
'bottomSheetTheme',
'popupMenuTheme',
'bannerTheme',
'dividerTheme',
'buttonBarTheme',
'bottomNavigationBarTheme',
'timePickerTheme',
'textButtonTheme',
'elevatedButtonTheme',
'outlinedButtonTheme',
'textSelectionTheme',
'dataTableTheme',
'checkboxTheme',
'radioTheme',
'switchTheme',
'progressIndicatorTheme',
'drawerTheme',
'listTileTheme',
'fixTextFieldOutlineLabel',
'useTextSelectionTheme',
'androidOverscrollIndicator',
};
final DiagnosticPropertiesBuilder properties = DiagnosticPropertiesBuilder();
ThemeData.light().debugFillProperties(properties);
final List<String> propertyNameList = properties.properties
.map((final DiagnosticsNode node) => node.name)
.whereType<String>()
.toList();
final Set<String> propertyNames = propertyNameList.toSet();
// Ensure there are no duplicates.
expect(propertyNameList.length, propertyNames.length);
// Ensure they are all there.
expect(propertyNames, expectedPropertyNames);
});
}
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