External windows in Flutter Windows apps
Windows lifecycle
Who is affected
#Windows applications built against Flutter versions after 3.13 that open non-Flutter windows.
Overview
#When adding a non-Flutter window to a Flutter Windows app, it will not be part of the logic for application lifecycle state updates by default. For example, this means that when the external window is shown or hidden, the app lifecycle state will not appropriately update to inactive or hidden. As a result, the app may receive incorrect lifecycle state changes through WidgetsBindingObserver.didChangeAppLifecycle.
What do I need to do?
To add the external window to this application logic,
the window's WndProc
procedure
must invoke FlutterEngine::ProcessExternalWindowMessage
.
To achieve this, add the following code to a window message handler function:
LRESULT Window::Messagehandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
std::optional<LRESULT> result = flutter_controller_->engine()->ProcessExternalWindowMessage(hwnd, msg, wparam, lparam);
if (result.has_value()) {
return *result;
}
// Original contents of WndProc...
}
除非另有说明,本文档之所提及适用于 Flutter 的最新稳定版本,本页面最后更新时间: 2024-08-16。 查看文档源码 或者 为本页面内容提出建议。