Upstream web support for IterableProperty<double>#37515
Upstream web support for IterableProperty<double>#37515ferhatb merged 2 commits intoflutter:masterfrom
Conversation
| return sb.toString(); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Why not support this without forking the cases for regular and double properties?
If you wrote
Iterable<String> formattedValues = value.map((T v) { return v is double ? debugFormatDouble : v.toString(); });Then you could reuse the existing logic for formatting the output in both the line break and regular cases. Someone might add an additional customization for formatting iterables in the future as the current options aren't always ideal so it would be nice to keep one copy of that code.
There was a problem hiding this comment.
Triggering the transform on whether T== double would also be fine with me. E.g
Iterable formattedValue = T == double ? value.map(debugFormatDouble) : value;
There was a problem hiding this comment.
Thank you for suggestion. I had tried value.map(debugFormatDouble) but it complained about closure, somehow T == double type check didn't flow through.
Very hard to pass flutter lint rules on this one since v as double is not allowed and T == double keeps v's type as T so you can pass without casting. So (T == double && v is double) was only way to unify since "v is double" won't work on web platform since int and double use num.
I updated the code to a simplified version.
| } | ||
| return '[${sb.toString()}]'; | ||
| final Iterable<String> formattedValues = value.map((T v) { | ||
| if (T == double && v is double) { |
There was a problem hiding this comment.
@munificent It is unfortunate Flutter lints are requiring this check when all we want to do is check.
Can we get the T == double check to flow through or correct the Flutter lints to not worry about sealed types like double?
There was a problem hiding this comment.
Checking the type parameter for each element doesn't make much sense to me. It's a property of the surrounding class, so it's going to be the same each time. Why not just do if (v is double)?
That accomplishes everything you're trying to express. If you really want to check the type argument, you could do:
Iterable<String> formattedValues;
if (T == double) {
formattedValues = value.map((T v) => debugFormatDouble(v as double));
} else {
formattedValues = value.map((T v) => v.toString());
}
But you still have to do some kind of runtime type check per element because Dart doesn't have anything like template specialization.
Description
table_rendering_test uses IterableProperty which fails on web platform due to default double.toString() behavior. This PR updates diagnostics to use debugFormatDouble to support web platform.
Related Issues
#37491
Tests
I added a test in diagnostics_test.dart for IterableProperty.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?