Use .fromMap() constructors in example code (#152535)
Currently, there are 21 `.resolveWith()` calls in example files.
This pull request changes 11 of them to use the new `.fromMap()` constructor. (Seven of them are now `const`!)
```dart
ListTile(
iconColor: WidgetStateColor.fromMap(<WidgetStatesConstraint, Color>{
WidgetState.disabled: Colors.red,
WidgetState.selected: Colors.green,
WidgetState.any: Colors.black,
}),
// The same can be achieved using the .resolveWith() constructor.
// The text color will be identical to the icon color above.
textColor: WidgetStateColor.resolveWith((Set<WidgetState> states) {
if (states.contains(WidgetState.disabled)) {
return Colors.red;
}
if (states.contains(WidgetState.selected)) {
return Colors.green;
}
return Colors.black;
}),
),
```
This commit is contained in:
@@ -45,19 +45,13 @@ class _ListTileExampleState extends State<ListTileExample> {
|
||||
_selected = !_selected;
|
||||
});
|
||||
},
|
||||
// This sets text color and icon color to red when list tile is disabled and
|
||||
// green when list tile is selected, otherwise sets it to black.
|
||||
iconColor: WidgetStateColor.resolveWith((Set<WidgetState> states) {
|
||||
if (states.contains(WidgetState.disabled)) {
|
||||
return Colors.red;
|
||||
}
|
||||
if (states.contains(WidgetState.selected)) {
|
||||
return Colors.green;
|
||||
}
|
||||
return Colors.black;
|
||||
iconColor: WidgetStateColor.fromMap(<WidgetStatesConstraint, Color>{
|
||||
WidgetState.disabled: Colors.red,
|
||||
WidgetState.selected: Colors.green,
|
||||
WidgetState.any: Colors.black,
|
||||
}),
|
||||
// This sets text color and icon color to red when list tile is disabled and
|
||||
// green when list tile is selected, otherwise sets it to black.
|
||||
// The same can be achieved using the .resolveWith() constructor.
|
||||
// The text color will be identical to the icon color above.
|
||||
textColor: WidgetStateColor.resolveWith((Set<WidgetState> states) {
|
||||
if (states.contains(WidgetState.disabled)) {
|
||||
return Colors.red;
|
||||
|
||||
Reference in New Issue
Block a user