-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
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== hoverColorshould 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
brightnessin thecopyWithparameter list is probably a remnant from whenbrightnessexisted inThemeDatadirectly. It should however be removed in current implementation fromcopyWithas a parameter.
| Brightness? brightness, |
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:
visualDensityprimaryColorLightprimaryColorDarksplashFactoryfixTextFieldOutlineLabeluseTextSelectionTheme
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
debugFillPropertiesdeviates significantly from the order of properties inoperator,hashCodeandThemeData.rawit 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.
