Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Godot View does not respect layout in flutter android app and always sticks to the top of the screen #11

Open
kyadalu1 opened this issue Dec 8, 2023 · 3 comments

Comments

@kyadalu1
Copy link

kyadalu1 commented Dec 8, 2023

I am trying to embed Godot view in my flutter android app. Here is the complete source code

Flutter allows embedding native views. Check here for more info

I am able to embed my godot view properly in my flutter app, but the issue is it always sticks at the top and hide other flutter contents.

Check below video to know what i am talking about

Screen.Recording.2023-12-08.at.8.43.34.AM.mov

As you can see in the video, first i had two flutter Text at the top and at the bottom. Once the Godot view loads it completely occupies the First text, there is a Positioned widget from flutter as well which is kind of like position: absolute property from css and the Godot view does not respect that as well. Also if you check my code i have specifically set the size of my framelayout which also does not work and the Godot view occupies the entire height of 1200 which i had set in my Godot project. The same thing works in Jetpack compose by setting framelayout height manually.

Here is a snippet of my code

My native view in flutter

class MyQrView(
    context: Context, id: Int, creationParams: Map<String?, Any?>?,
    private val activity: FlutterFragmentActivity
) : PlatformView {
    private val linearLayout: LinearLayout
    private val frameLayout: FrameLayout

    override fun getView(): View {
        return linearLayout
    }

    override fun dispose() {}

    init {
        linearLayout = LinearLayout(context)
        linearLayout.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
        )
        frameLayout = FrameLayout(context)
        frameLayout.id = View.generateViewId()

        linearLayout.addView(frameLayout)

        frameLayout.apply {
            frameLayout.layoutParams.height = 300
            val fragmentTransaction = activity.supportFragmentManager.beginTransaction()
            fragmentTransaction.replace(frameLayout.id, GodotFragment())
            fragmentTransaction.commit()
        }
    }


}

To use it in flutter i use something like this

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    var width = MediaQuery.of(context).size.width;
    var height = MediaQuery.of(context).size.height;
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: [
            Text(
              "Hello from flutter",
              style: TextStyle(fontSize: 20),
            ),
            Positioned(
              top: 100,
              child: SizedBox(
                width: width,
                height: height / 1.5,
                child: MyQrView(),
              ),
            ),
            Text(
              "Hello from flutter",
              style: TextStyle(fontSize: 20),
            ),
          ],
        ),
      ),
    );
  }
}

The column widget in flutter helps to layout views on below the other which the Godot view does not respect. I have created multiple platforms views previously for android using flutter and have never faced such problem. This seems like a Godot issue to me than a flutter issue. Correct me if i am wrong

@albrechetti
Copy link

I watched the tutorials, but when attempting to run the project in Godot 4.2.1, I encountered difficulties similar to what you demonstrated. However, upon invoking the Godot Screen, the application abruptly halts and shuts down the emulator. Below is the error output:

Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:62352/Unj3fz0AB-g=/ws
D/ProfileInstaller( 4292): Installing profile for com.example.project_001_godot
D/AppCompatDelegate( 4292): Checking for metadata for AppLocalesMetadataHolderService : Service not found
W/oject_001_godo( 4292): Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (unsupported, reflection, allowed)
W/oject_001_godo( 4292): Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (unsupported, reflection, allowed)
E/godot ( 4292): USER ERROR: Couldn't load file 'res://project.binary', error code 19.
E/godot ( 4292): at: _load_settings_text_or_binary (core/config/project_settings.cpp:783)
I/godot ( 4292): Godot Engine v4.2.1.stable.official.b09f793f5 - https://godotengine.org
D/HostConnection( 4292): createUnique: call
D/HostConnection( 4292): HostConnection::get() New Host Connection established 0x72aff97fad50, tid 4654
D/HostConnection( 4292): 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_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri 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/vulkan ( 4292): searching for layers in '/data/app/~~E6kxmACb6XgiuVwCnUqCBw==/com.example.project_001_godot-vmeFX-iVbcibaoWswp7Dfg==/lib/x86_64'
D/vulkan ( 4292): searching for layers in '/data/app/~~E6kxmACb6XgiuVwCnUqCBw==/com.example.project_001_godot-vmeFX-iVbcibaoWswp7Dfg==/base.apk!/lib/x86_64'
I/godot ( 4292): Vulkan API 1.3.0 - Forward Mobile - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce RTX 2060
D/goldfish_vulkan( 4292): on_vkEnumerateDeviceExtensionProperties: host has ext semaphore? win32 1 posix 0
D/goldfish_vulkan( 4292): on_vkEnumerateDeviceExtensionProperties: host has ext semaphore? win32 1 posix 0
D/goldfish_vulkan( 4292): on_vkEnumerateDeviceExtensionProperties: host has ext semaphore? win32 1 posix 0
D/goldfish_vulkan( 4292): on_vkEnumerateDeviceExtensionProperties: host has ext semaphore? win32 1 posix 0
D/goldfish_vulkan( 4292): on_vkEnumerateDeviceExtensionProperties: host has ext semaphore? win32 1 posix 0
D/goldfish_vulkan( 4292): on_vkEnumerateDeviceExtensionProperties: host has ext semaphore? win32 1 posix 0
D/goldfish_vulkan( 4292): on_vkEnumerateDeviceExtensionProperties: host has ext semaphore? win32 1 posix 0
D/goldfish_vulkan( 4292): on_vkEnumerateDeviceExtensionProperties: host has ext semaphore? win32 1 posix 0
D/goldfish_vulkan( 4292): on_vkEnumerateDeviceExtensionProperties: host has ext semaphore? win32 1 posix 0
D/goldfish_vulkan( 4292): on_vkEnumerateDeviceExtensionProperties: host has ext semaphore? win32 1 posix 0
D/goldfish-address-space( 4292): allocate: Ask for block of size 0x1000000
D/goldfish-address-space( 4292): allocate: ioctl allocate returned offset 0x3f2fff000 size 0x1001000
I/godot ( 4292):
D/oject_001_godo( 4292): PlayerBase::PlayerBase()
D/oject_001_godo( 4292): TrackPlayerBase::TrackPlayerBase()
I/libOpenSLES( 4292): Emulating old channel mask behavior (ignoring positional mask 0x3, using default mask 0x3 based on channel count of 2)
D/AudioTrack( 4292): createTrack_l(0): AUDIO_OUTPUT_FLAG_FAST denied by server; frameCount 0 -> 1956
D/Godot ( 4292): OnGodotSetupCompleted
D/Godot ( 4292): OnGodotMainLoopStarted
E/godot ( 4292): USER ERROR: Condition "header != String(shader_file_header)" is true. Returning: false
E/godot ( 4292): at: _load_from_cache (servers/rendering/renderer_rd/shader_rd.cpp:409)
D/HostConnection( 4292): createUnique: call
D/HostConnection( 4292): HostConnection::get() New Host Connection established 0x72aff97fd690, tid 4652
D/HostConnection( 4292): 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_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri 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/HostConnection( 4292): createUnique: call
D/HostConnection( 4292): HostConnection::get() New Host Connection established 0x72aff97fce50, tid 4653
D/HostConnection( 4292): 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_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri 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/HostConnection( 4292): createUnique: call
D/HostConnection( 4292): HostConnection::get() New Host Connection established 0x72aff97f8f50, tid 4651
D/HostConnection( 4292): 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_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri 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/HostConnection( 4292): createUnique: call
D/HostConnection( 4292): HostConnection::get() New Host Connection established 0x72aff97fbd10, tid 4650
D/HostConnection( 4292): 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_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri 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
Lost connection to device.

Exited.

@BraveEvidence
Copy link

You can follow this, of course it has the same issue highlighted but the original author but I think you should try running it on a real device and not emulator

@54cz
Copy link

54cz commented Sep 14, 2024

Screenshot_20240914_154543
Ran your project and found no issues, perhaps the Godot engine has been updated? Try syncing the project with Gradle files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants