Skip to content

Commit

Permalink
Handle all possible values of StrokePoint.t (flutter-ml#316)
Browse files Browse the repository at this point in the history
Flutter serializes all integers less than 2^32 [as an `int` instead of a `long`](https://docs.flutter.dev/development/platform-integration/platform-channels?tab=type-mappings-java-tab), so trying to pass a small number as `t` causes a `ClassCastException` here (see flutter-ml#242, which was prematurely closed by the OP).

This probably happens all over the place and should be put in a helper method and sprinkled throughout the codebase, but this is the only place I've encountered it so far.
  • Loading branch information
ecstatic-morse authored Aug 23, 2022
1 parent afa2444 commit 5fc3b3d
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ private void handleDetection(MethodCall call, final MethodChannel.Result result)
for (final Map<String, Object> point : pointsList) {
float x = (float) (double) point.get("x");
float y = (float) (double) point.get("y");
long t = (long) point.get("t");
Object t0 = point.get("t");
long t;
if (t0 instanceof Integer) {
t = (int) t0;
} else {
t = (long) t0;
}
Ink.Point strokePoint = Ink.Point.create(x, y, t);
strokeBuilder.addPoint(strokePoint);
}
Expand Down

0 comments on commit 5fc3b3d

Please sign in to comment.