跳至主要內容

遷移 Windows 專案以確保視窗顯示

Flutter 3.13 修正了一個可能導致視窗無法顯示的 錯誤。使用 Flutter 3.7 或 Flutter 3.10 建立的 Windows 專案需要遷移以修正此問題。

遷移步驟

#

使用 flutter --version 確認您使用的是 Flutter 3.13 或更新版本。如果需要,請使用 flutter upgrade 更新至最新版本的 Flutter SDK。

未修改其 windows/runner/flutter_window.cpp 檔案的專案將由 flutter runflutter build windows 自動遷移。

已修改其 windows/runner/flutter_window.cpp 檔案的專案可能需要手動遷移。

遷移前的程式碼

cpp
flutter_controller_->engine()->SetNextFrameCallback([&]() {
  this->Show();
});

遷移後的程式碼

cpp
flutter_controller_->engine()->SetNextFrameCallback([&]() {
  this->Show();
});

// Flutter can complete the first frame before the "show window" callback is
// registered. The following call ensures a frame is pending to ensure the
// window is shown. It is a no-op if the first frame hasn't completed yet.
flutter_controller_->ForceRedraw();

範例

#

PR 995 顯示了 Flutter Gallery 應用程式的遷移工作。