flutter_window.cpp 892 B

1234567891011121314151617181920212223242526272829
  1. #include "flutter_window.h"
  2. #include "flutter/generated_plugin_registrant.h"
  3. FlutterWindow::FlutterWindow(RunLoop* run_loop,
  4. const flutter::DartProject& project)
  5. : run_loop_(run_loop), project_(project) {}
  6. FlutterWindow::~FlutterWindow() {}
  7. void FlutterWindow::OnCreate() {
  8. Win32Window::OnCreate();
  9. // The size here is arbitrary since SetChildContent will resize it.
  10. flutter_controller_ =
  11. std::make_unique<flutter::FlutterViewController>(100, 100, project_);
  12. RegisterPlugins(flutter_controller_.get());
  13. run_loop_->RegisterFlutterInstance(flutter_controller_.get());
  14. SetChildContent(flutter_controller_->view()->GetNativeWindow());
  15. }
  16. void FlutterWindow::OnDestroy() {
  17. if (flutter_controller_) {
  18. run_loop_->UnregisterFlutterInstance(flutter_controller_.get());
  19. flutter_controller_ = nullptr;
  20. }
  21. Win32Window::OnDestroy();
  22. }