Upstream web support for IterableProperty<double> (#37515)
* Upstream web support for IterableProperty<double>
This commit is contained in:
@@ -2217,20 +2217,28 @@ class IterableProperty<T> extends DiagnosticsProperty<Iterable<T>> {
|
||||
);
|
||||
|
||||
@override
|
||||
String valueToString({ TextTreeConfiguration parentConfiguration }) {
|
||||
String valueToString({TextTreeConfiguration parentConfiguration}) {
|
||||
if (value == null)
|
||||
return value.toString();
|
||||
|
||||
if (value.isEmpty)
|
||||
return ifEmpty ?? '[]';
|
||||
|
||||
final Iterable<String> formattedValues = value.map((T v) {
|
||||
if (T == double && v is double) {
|
||||
return debugFormatDouble(v);
|
||||
} else {
|
||||
return v.toString();
|
||||
}
|
||||
});
|
||||
|
||||
if (parentConfiguration != null && !parentConfiguration.lineBreakProperties) {
|
||||
// Always display the value as a single line and enclose the iterable
|
||||
// value in brackets to avoid ambiguity.
|
||||
return '[${value.join(', ')}]';
|
||||
return '[${formattedValues.join(', ')}]';
|
||||
}
|
||||
|
||||
return value.join(_isSingleLine(style) ? ', ' : '\n');
|
||||
return formattedValues.join(_isSingleLine(style) ? ', ' : '\n');
|
||||
}
|
||||
|
||||
/// Priority level of the diagnostic used to control which diagnostics should
|
||||
|
||||
@@ -1611,6 +1611,15 @@ void main() {
|
||||
expect(intsProperty.isFiltered(DiagnosticLevel.info), isFalse);
|
||||
expect(intsProperty.toString(), equals('ints: 1, 2, 3'));
|
||||
|
||||
final List<double> doubles = <double>[1,2,3];
|
||||
final IterableProperty<double> doublesProperty = IterableProperty<double>(
|
||||
'doubles',
|
||||
doubles,
|
||||
);
|
||||
expect(doublesProperty.value, equals(doubles));
|
||||
expect(doublesProperty.isFiltered(DiagnosticLevel.info), isFalse);
|
||||
expect(doublesProperty.toString(), equals('doubles: 1.0, 2.0, 3.0'));
|
||||
|
||||
final IterableProperty<Object> emptyProperty = IterableProperty<Object>(
|
||||
'name',
|
||||
<Object>[],
|
||||
|
||||
Reference in New Issue
Block a user