jiusanzhou / flutter_floatwing

A Flutter plugin that makes it easier to make floating/overlay window for Android with pure Flutter. 一个可以用纯粹的Flutter来开发Android浮动窗口的插件。
Other
169 stars 28 forks source link

fix int to long conversion #15

Closed psovit closed 1 year ago

psovit commented 1 year ago

Fix for java.lang.ClassCastException in Flutter environment : sdk: ">=2.12.0 <3.0.0". Reference to issue: java.lang.ClassCastException in Flutter environment : sdk: ">=2.12.0 <3.0.0".

Solved by first casting to Int? and then to Long?.

jiusanzhou commented 1 year ago

@psovit Thank you for great work. What's your Flutter version? I think we need to keep it works both in Flutter 2 and Flutter 3.

psovit commented 1 year ago

Hi @jiusanzhou , Here's my Flutter version info:

Flutter 3.0.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision fb57da5f94 (7 months ago) • 2022-05-19 15:50:29 -0700
Engine • revision caaafc5604
Tools • Dart 2.17.1 • DevTools 2.12.2

Please feel free to modify this merge request or handle the issue on your own way 👍

If you could update the plugin with the fix, that would be really helpful as I am currently in need of this package :)

psovit commented 1 year ago

HI @jiusanzhou , I am still checking out the package and the change I submitted. I would suggest you also make sure my change is working before publishing the package as I am still seeing some related issues...

jiusanzhou commented 1 year ago

@psovit ok, thank you for PR, I will do some recheck before publishing it in few days later.

mulaRahul commented 1 year ago

Hello @jiusanzhou, @psovit, I was checking the example app when I encountered the below error -

logs of interest

D/FloatWindow(26278): [window] start window: assitive_touch
...
D/FloatWindow(26278): [window] update window assitive_touch => {entry=main, width=154, height=154}
E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): Failed to handle method call
E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278):    at im.zoe.labs.flutter_floatwing.FloatWindow$Config$Companion.from(FloatWindow.kt:502)
Full Logs ``` D/FloatwingService(26278): [service] window.start request_id: assitive_touch {system={pixelRadio=2, screen={width=1080, height=2148}}, pixelRadio=2.75, id=assitive_touch, config={focusable=false, entry=main, route=/assitive_touch, draggable=true}} D/FloatWindow(26278): [window] start window: assitive_touch W/Gralloc4(26278): allocator 3.x is not supported D/HostConnection(26278): HostConnection::get() New Host Connection established 0xf0e23a20, tid 26347 D/HostConnection(26278): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 D/EGL_emulation(26278): eglMakeCurrent: 0xf0e0d670: ver 3 0 (tinfo 0xbe0a6730) (first time) D/EGL_emulation(26278): eglCreateContext: 0xf0e15fd0: maj 3 min 0 rcv 3 D/FloatWindow(26278): [window] window.update request_id: assitive_touch, my_id: assitive_touch D/FloatWindow(26278): [window] update window assitive_touch => {entry=main, width=154, height=154} D/FloatWindow(26278): [window] window.update request_id: assitive_touch, my_id: assitive_touch D/FloatWindow(26278): [window] update window assitive_touch => {entry=main, width=154, height=154} E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): Failed to handle method call E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): at im.zoe.labs.flutter_floatwing.FloatWindow$Config$Companion.from(FloatWindow.kt:502) E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): at im.zoe.labs.flutter_floatwing.FloatWindow.onMethodCall(FloatWindow.kt:221) E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319) E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12) E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): at android.os.Handler.handleCallback(Handler.java:938) E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): at android.os.Handler.dispatchMessage(Handler.java:99) E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): at android.os.Looper.loop(Looper.java:223) E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): at android.app.ActivityThread.main(ActivityThread.java:7656) E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) E/MethodChannel#im.zoe.labs/flutter_floatwing/window(26278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) E/flutter (26278): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, java.lang.Long cannot be cast to java.lang.Integer, null, java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer E/flutter (26278): at im.zoe.labs.flutter_floatwing.FloatWindow$Config$Companion.from(FloatWindow.kt:502) E/flutter (26278): at im.zoe.labs.flutter_floatwing.FloatWindow.onMethodCall(FloatWindow.kt:221) E/flutter (26278): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) E/flutter (26278): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) E/flutter (26278): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319) E/flutter (26278): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12) E/flutter (26278): at android.os.Handler.handleCallback(Handler.java:938) E/flutter (26278): at android.os.Handler.dispatchMessage(Handler.java:99) E/flutter (26278): at android.os.Looper.loop(Looper.java:223) E/flutter (26278): at android.app.ActivityThread.main(ActivityThread.java:7656) E/flutter (26278): at java.lang.reflect.Method.invoke(Native Method) E/flutter (26278): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) E/flutter (26278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) E/flutter (26278): ) E/flutter (26278): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7) E/flutter (26278): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18) E/flutter (26278): E/flutter (26278): #2 MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:499:43) E/flutter (26278): E/flutter (26278): #3 FloatwingPlugin.internalCreateWindow (package:flutter_floatwing/src/plugin.dart:192:19) E/flutter (26278): E/flutter (26278): #4 FloatwingPlugin.createWindow (package:flutter_floatwing/src/plugin.dart:160:11) E/flutter (26278): E/flutter (26278): #5 Window.create (package:flutter_floatwing/src/window.dart:93:12) E/flutter (26278): E/flutter (26278): ```

In short, if you run the example app (with the main branch) and Open the assitive_touch route, the above will be the exceptions. Visually, there's nothing noticeable but if you use VS Code to debug, it will catch the error. (It should also be noted that if you Close the route, and re-Open it, no exceptions are raised)

I looked at the #3 and found this PR. Now the error says java.lang.Long cannot be cast to java.lang.Integer so I used the old cast i.e.

cfg.callback = data["callback"] as Long?

and conveniently the exception goes away as well.

At all, I'm a bit confused. This PR should resolve the issue that was arising before, but now maybe it's raising another one or maybe not. Do let me know if I'm missing something here and excuse my insufficient knowledge on kotlin.

jiusanzhou commented 1 year ago

Hi @mulaRahul Thank you for information, I think that is I had made some mistake on this fixing. I will retest it and try to figure it out.