un-break ThemeData equality (#154695)

This PR is _almost_ able to close issue #89127.

Sadly, no `InheritedModel` or custom `RenderObject`s today; instead the [WidgetState operators](https://main-api.flutter.dev/flutter/widgets/WidgetStateOperators.html) have been restructured to support equality checks.

`WidgetStateProperty.fromMap()` is now capable of accurate equality checks, and all of the `.styleFrom()` methods have been refactored to use that constructor.

(Equality checks are still broken for `WidgetStateProperty.resolveWith()`, and any other non-`const` objects that implement the interface.)

<br><br>

credit for this idea goes to @justinmc: https://github.com/flutter/flutter/issues/89127#issuecomment-2313187703
This commit is contained in:
Nate Wilson
2024-09-09 15:49:09 -06:00
committed by GitHub
parent 18c325af17
commit bfa04edca6
13 changed files with 360 additions and 564 deletions

View File

@@ -30,8 +30,8 @@ class MaterialStateExample extends StatelessWidget {
Widget build(BuildContext context) {
return TextFormField(
initialValue: 'abc',
decoration: InputDecoration(
prefixIcon: const Icon(Icons.person),
decoration: const InputDecoration(
prefixIcon: Icon(Icons.person),
prefixIconColor: WidgetStateColor.fromMap(
<WidgetStatesConstraint, Color>{
WidgetState.focused: Colors.green,

View File

@@ -32,7 +32,7 @@ class MaterialStateExample extends StatelessWidget {
return Theme(
data: themeData.copyWith(
inputDecorationTheme: themeData.inputDecorationTheme.copyWith(
prefixIconColor: WidgetStateColor.fromMap(
prefixIconColor: const WidgetStateColor.fromMap(
<WidgetStatesConstraint, Color>{
WidgetState.error: Colors.red,
WidgetState.focused: Colors.blue,

View File

@@ -45,7 +45,7 @@ class _ListTileExampleState extends State<ListTileExample> {
_selected = !_selected;
});
},
iconColor: WidgetStateColor.fromMap(<WidgetStatesConstraint, Color>{
iconColor: const WidgetStateColor.fromMap(<WidgetStatesConstraint, Color>{
WidgetState.disabled: Colors.red,
WidgetState.selected: Colors.green,
WidgetState.any: Colors.black,