Skip to content

ThemeData issues with operator, copyWith and debugFillProperties #91587

@rydmike

Description

@rydmike

ThemeData Class has the following issues

1) Two properties are missing from == operator override

The properties:

  • focusColor
  • hoverColor

That exists as properties in ThemeData.raw and in hashCode are missing from operator. The lines:

        && other.focusColor== focusColor
        && other.hoverColor== hoverColor

should be added to operator.

The current operator implementation will cause issues. I had some, and it led me to investigate these overrides more closely, which is why I found this and the other issues in this report.

2) copyWith includes brightness parameter

The brightness is a getter in ThemeData that returns brightness from ThemeData.colorScheme. It can thus not be modified with a copyWith of ThemeData, nor does returned ThemeData.raw from the copyWith include any brightness value!

If somebody tries to modify theme brightness with this copyWith, they will not succeed and "might" be confused.

The brightness in the copyWith parameter list is probably a remnant from when brightness existed in ThemeData directly. It should however be removed in current implementation from copyWith as a parameter.

3) debugFillProperties has the following issues

The textSelectionTheme is added to it twice, as two consecutive rows:

properties.add(DiagnosticsProperty<TextSelectionThemeData>('textSelectionTheme', textSelectionTheme, defaultValue: defaultData.textSelectionTheme, level: DiagnosticLevel.debug));

properties.add(DiagnosticsProperty<TextSelectionThemeData>('textSelectionTheme', textSelectionTheme, defaultValue: defaultData.textSelectionTheme, level: DiagnosticLevel.debug));

The following ThemeData properties are missing from debugFillProperties:

  • visualDensity
  • primaryColorLight
  • primaryColorDark
  • splashFactory
  • fixTextFieldOutlineLabel
  • useTextSelectionTheme

For correct toString() and debug DevTools, functionality the extra entry of textSelectionTheme should be removed and the missing properties added.

The debugFillProperties also includes brightness, but since it is not a property of ThemeData it should be removed.

properties.add(EnumProperty<Brightness>('brightness', brightness, defaultValue: defaultData.brightness, level: DiagnosticLevel.debug));

  • Observation: The order of the properties in debugFillProperties deviates significantly from the order of properties in operator, hashCode and ThemeData.raw it would be helpful if they were in the same order.

How to Reproduce

The above errors can be observed in the source code in all current versions from stable 2.5.2 and all channels up to master 2.6.0-12.0.pre.287.

Issue Visualized

The attached image table shows the issues. In order to easier compare and find what was going on with the
properties I copy-pasted the props in the image from ThemeData from master channel, into a table in order to compare and easier see what is going. I added it here as well, but the found issues are summarized above and fixes are straight forward.

In the table the debugFillProperites have been manually re-ordered into same order as the other methods properties, to be able to see the gaps more easily. I recommend putting them in the same order in the code as well.

Turns out that the parameters to copyWith and its return values, are not in the same order and neither of them agrees with the order used on ThemeData.raw, operator and hashCode. The copyWith params and return order that are off, in relation to them are marked in green. They are shown in the order they appeared in the code. They are all there though, so no issue, but again, same order would be nice.

image

Metadata

Metadata

Assignees

Labels

f: material designflutter/packages/flutter/material repository.found in release: 2.5Found to occur in 2.5found in release: 2.6Found to occur in 2.6frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions