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

无法获取window #11

Closed
LondonX opened this issue Aug 5, 2022 · 2 comments
Closed

无法获取window #11

LondonX opened this issue Aug 5, 2022 · 2 comments

Comments

@LondonX
Copy link

LondonX commented Aug 5, 2022

你好,我的App通过entry-point方式开启悬浮窗,悬浮窗包含在GetMaterialApp中。
在悬浮窗的SchedulerBinding.instance.addPostFrameCallback调用Window.of(context)和FloatwingPlugin().currentWindow都返回null。
调用syncWindows()后再通过windows["xxxID"]可以获取window对象,但不会回调onData。

版本信息
flutter_floatwing: ^0.2.1
Flutter: 3.0.5

@jiusanzhou
Copy link
Owner

Hi, 你可能需要一些初始化才能获取window对象。

In your window engine, you can access the window object in 2 ways:

Directly access the cache field of plugin: FloatwingPlugin().currentWindow.
If widget injected by .floatwing(), you can take window with Window.of(context).

可以提供一下你的window的代码吗?

@LondonX
Copy link
Author

LondonX commented Aug 8, 2022

获取对象相关代码已删除,目前解决方案是通过Android广播机制来传值。

初始化悬浮窗(main.dart中)

@pragma("vm:entry-point")
void overlayPlayer() {
  runApp(const OverlayApp(
    child: OverlayPlayerView(),
  ));
}
@pragma("vm:entry-point")
void overlayDestroyer() {
  runApp(const OverlayApp(
    child: OverlayDestroyer(),
  ));
}

显示悬浮窗

await WindowConfig(
      entry: "overlayPlayer",
      draggable: true,
      clickable: true,
      focusable: false,
      height: (_playerSize * _pxRatio).round(),
      width: (_playerSize * _pxRatio).round(),
      id: "overlayPlayer",
      x: (_screenSize.width - _playerSize * _pxRatio).round(),
      y: (_screenSize.height / 2 + 100).round(),
      immersion: true,
    ).to().create(start: true)
await WindowConfig(
      entry: "overlayDestroyer",
      draggable: false,
      clickable: false,
      focusable: false,
      height: (100 * _pxRatio).round(),
      width: (_screenSize.width).round(),
      y: (_screenSize.height - 100 * _pxRatio).round(),
      id: "overlayDestroyer",
      immersion: true,
    ).to().create(start: true);

@LondonX LondonX closed this as completed Sep 30, 2022
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

2 participants