Skip to content

Commit 5833714

Browse files
authored
Fix narrowing conversion lint (flutter#47740)
Internally we have a lint that surfaces this as a warning. Googlers, please refer to go/al-rule/NarrowingConversion. Related: b/309552840 When we do: ``` coords.toolMajor = (float) (double) coordsList.get(3) * density; ``` `coordsList.get(3)` is casted to a `double`, then a `float`, before the multiplication happens. I don't think this is intentional. The intention of the code here seems to be: - Cast to a `double`: `coordsList` is a `List<Object>` so the cast narrows the value - Cast to a `float`: To fit the resulting value into [`coords.toolMajor`](https://developer.android.com/reference/android/view/MotionEvent.PointerCoords#toolMajor), which is a `float`. As such, add parenthesis to address this. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent b6acdc7 commit 5833714

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,12 +1027,12 @@ private static PointerCoords parsePointerCoords(Object rawCoords, float density)
10271027
coords.orientation = (float) (double) coordsList.get(0);
10281028
coords.pressure = (float) (double) coordsList.get(1);
10291029
coords.size = (float) (double) coordsList.get(2);
1030-
coords.toolMajor = (float) (double) coordsList.get(3) * density;
1031-
coords.toolMinor = (float) (double) coordsList.get(4) * density;
1032-
coords.touchMajor = (float) (double) coordsList.get(5) * density;
1033-
coords.touchMinor = (float) (double) coordsList.get(6) * density;
1034-
coords.x = (float) (double) coordsList.get(7) * density;
1035-
coords.y = (float) (double) coordsList.get(8) * density;
1030+
coords.toolMajor = (float) ((double) coordsList.get(3) * density);
1031+
coords.toolMinor = (float) ((double) coordsList.get(4) * density);
1032+
coords.touchMajor = (float) ((double) coordsList.get(5) * density);
1033+
coords.touchMinor = (float) ((double) coordsList.get(6) * density);
1034+
coords.x = (float) ((double) coordsList.get(7) * density);
1035+
coords.y = (float) ((double) coordsList.get(8) * density);
10361036
return coords;
10371037
}
10381038

0 commit comments

Comments
 (0)