if chains → switch expressions (#147793)

Previous "if-chains" pull requests:
- https://github.com/flutter/flutter/pull/144905
- https://github.com/flutter/flutter/pull/144977
- https://github.com/flutter/flutter/pull/145194
- https://github.com/flutter/flutter/pull/146293
- https://github.com/flutter/flutter/pull/147472

<br>

I think this one should be enough to wrap things up!

fixes https://github.com/flutter/flutter/issues/144903

---------

Co-authored-by: Victor Sanni <victorsanniay@gmail.com>
This commit is contained in:
Nate
2024-05-10 00:55:48 -06:00
committed by GitHub
parent c90e18c6f5
commit 4734d80f22
33 changed files with 194 additions and 297 deletions

View File

@@ -169,16 +169,13 @@ abstract class TokenTemplate {
}
String? _numToString(Object? value, [int? digits]) {
if (value == null) {
return null;
}
if (value is num) {
if (value == double.infinity) {
return 'double.infinity';
}
return digits == null ? value.toString() : value.toStringAsFixed(digits);
}
return getToken(value as String).toString();
return switch (value) {
null => null,
double.infinity => 'double.infinity',
num() when digits == null => value.toString(),
num() => value.toStringAsFixed(digits!),
_ => getToken(value as String).toString(),
};
}
/// Generate an elevation value for the given component token.

View File

@@ -205,18 +205,11 @@ Map<String, String> reverseMapOfListOfString(Map<String, List<String>> inMap, vo
///
/// Will modify the input map.
Map<String, dynamic> removeEmptyValues(Map<String, dynamic> map) {
return map..removeWhere((String key, dynamic value) {
if (value == null) {
return true;
}
if (value is Map<String, dynamic>) {
final Map<String, dynamic> regularizedMap = removeEmptyValues(value);
return regularizedMap.isEmpty;
}
if (value is Iterable<dynamic>) {
return value.isEmpty;
}
return false;
return map..removeWhere((String key, dynamic value) => switch (value) {
null => true,
Map<String, dynamic>() => removeEmptyValues(value).isEmpty,
Iterable<dynamic>() => value.isEmpty,
_ => false,
});
}