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

无法获取window #11

Closed LondonX closed 2 years ago

LondonX commented 2 years ago

你好,我的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 commented 2 years ago

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 commented 2 years ago

获取对象相关代码已删除,目前解决方案是通过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);