android and windows targets

This commit is contained in:
yves committed 2026-11-07 15:48:01 +01:00
1 parent c069b8945d
commit 1d974b42a1
58 files changed
+2601 -111

No files matched your search

+26 -5
View File
@@ -1,6 +1,6 @@
# CLAUDE.md
Flutter **plugin** (Linux desktop only) embedding a CesiumJS globe. The
Flutter **plugin** (Linux, Android, Windows) embedding a CesiumJS globe. The
package is meant to be imported by other apps: keep the public API in
`lib/cesiumjs.dart` small and stable; everything else stays in `lib/src/`.
`example/` is the test/demo app, not part of the package.
@@ -10,15 +10,26 @@ package is meant to be imported by other apps: keep the public API in
```sh
flutter pub get && flutter analyze && flutter test # package (root)
cd example && flutter build linux --debug # compiles the native plugin
cd example && flutter build apk --debug # compiles the Kotlin plugin
cd example && flutter run -d linux --dart-define-from-file=cesium_ion.json
```
Native build needs `libwebkit2gtk-4.1-dev`. Native code is only compiled
through the example app — after changing `linux/cesiumjs_plugin.cc`, always
run `flutter build linux` in `example/`.
through the example app — after changing `linux/cesiumjs_plugin.cc` or
`android/`, always run the matching `flutter build` in `example/`.
`windows/cesiumjs_plugin.cpp` cannot be built from Linux (needs MSVC); it
compiles with `/W4 /WX`, so avoid unused parameters, shadowed names and
narrowing.
Android test emulator: AVD `cesium_test` (API 35, x86_64), lives in
`~/.config/.android/avd` → start with
`ANDROID_AVD_HOME=~/.config/.android/avd ~/Android/Sdk/emulator/emulator -avd cesium_test`.
## Architecture
All platforms share the `cesiumjs/webview` channel protocol (`create`
eagerly builds the web view keyed by a Dart id; other calls address it by id).
- `CesiumViewer` (Dart) renders a black placeholder and reports its global
rect after each paint (`_RenderRectReporter`) → `setRect` over the
`cesiumjs/webview` method channel.
@@ -28,7 +39,17 @@ run `flutter build linux` in `example/`.
`openInspector`, `dispose`, `disposeAll` (called once per isolate so hot
restart doesn't leave orphan views). Events back to Dart: `onMessage`,
`onError`.
- JS → Dart: `CesiumChannel.postMessage` → `window.webkit.messageHandlers.cesium`.
- Android (`android/…/CesiumjsPlugin.kt`): `create` builds an
`android.webkit.WebView`; the widget then shows it with an `AndroidView`
(view type `cesiumjs/webview`, creation param `id`). `setRect` is a no-op.
Flutter widgets *can* paint over the globe here.
- Windows (`windows/cesiumjs_plugin.cpp`): WebView2 in a host child window,
sibling of the Flutter view, placed at `rect * scale` (Dart sends
`devicePixelRatio` as `scale`). Page served from `https://cesium.localhost/`
via `WebResourceRequested`. WebView2 SDK downloaded from NuGet by CMake.
- JS → Dart: `CesiumChannel.postMessage` → `window.webkit.messageHandlers.cesium`
(Linux), `window.CesiumAndroid.postMessage` (Android),
`window.chrome.webview.postMessage` (Windows).
Messages are JSON with a `type` field → `CesiumMessage`.
- HTML is generated in `lib/src/cesium_html.dart` and loaded with
`load_html` + base URI `https://cesium.localhost/`; CesiumJS comes from
@@ -46,7 +67,7 @@ run `flutter build linux` in `example/`.
native child window, GTK3 composites WebKit with the FlView GL surface and
only ~0.2 frames/s reach the screen (Cesium's own FPS counter still says
60 — measure presented frames with ffmpeg x11grab + mpdecimate instead).
- Flutter widgets cannot paint over the globe; use `visible: false`.
- Linux/Windows: Flutter widgets cannot paint over the globe; use `visible: false`.
- `runJavaScript` cannot return a Promise as the last expression; scripts that
return nothing should end with `undefined;`.
- Controller internals (`attach`, `detach`, `handleMessage`) are `@internal`.