diff --git a/examples/platform_view/lib/main.dart b/examples/platform_view/lib/main.dart index b9d6edf6ca..00b3c48163 100644 --- a/examples/platform_view/lib/main.dart +++ b/examples/platform_view/lib/main.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'dart:async'; -import 'dart:io'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -47,6 +47,21 @@ class _MyHomePageState extends State { }); } + static Widget get _buttonText { + switch (defaultTargetPlatform) { + case TargetPlatform.android: + return const Text('Continue in Android view'); + case TargetPlatform.iOS: + return const Text('Continue in iOS view'); + case TargetPlatform.windows: + return const Text('Cotninue in Windows view'); + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.macOS: + throw UnimplementedError('Platform not yet implemented'); + } + } + Future _launchPlatformCount() async { final int? platformCounter = await _methodChannel.invokeMethod('switchView', _counter); @@ -76,9 +91,7 @@ class _MyHomePageState extends State { padding: const EdgeInsets.all(18.0), child: ElevatedButton( onPressed: _launchPlatformCount, - child: Platform.isIOS - ? const Text('Continue in iOS view') - : const Text('Continue in Android view'), + child: _buttonText, ), ), ], diff --git a/examples/platform_view/windows/CMakeLists.txt b/examples/platform_view/windows/CMakeLists.txt index 4aded10d73..f8a5f5f6fd 100644 --- a/examples/platform_view/windows/CMakeLists.txt +++ b/examples/platform_view/windows/CMakeLists.txt @@ -60,6 +60,9 @@ add_subdirectory("runner") # them to the application. include(flutter/generated_plugins.cmake) +target_include_directories(${BINARY_NAME} INTERFACE + "${CMAKE_CURRENT_SOURCE_DIR}/flutter") +target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_plugin) # === Installation === # Support files are copied into place next to the executable, so that it can @@ -84,6 +87,7 @@ install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR} install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) +set(PLUGIN_BUNDLED_LIBRARIES) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" diff --git a/examples/platform_view/windows/runner/flutter_window.cpp b/examples/platform_view/windows/runner/flutter_window.cpp index 9cbd3109c3..643a1c3cad 100644 --- a/examples/platform_view/windows/runner/flutter_window.cpp +++ b/examples/platform_view/windows/runner/flutter_window.cpp @@ -4,10 +4,38 @@ #include "flutter_window.h" +#include +#include +#include +#include +#include + +#include +#include #include +#include #include "flutter/generated_plugin_registrant.h" +void RegisterMethodChannel(flutter::FlutterEngine* engine) { + FlutterDesktopPluginRegistrarRef plugin_registrar_ref = + engine->GetRegistrarForPlugin("platform_view"); + flutter::PluginRegistrarWindows* registrar = + flutter::PluginRegistrarManager::GetInstance() + ->GetRegistrar(plugin_registrar_ref); + auto channel = + std::make_unique>( + registrar->messenger(), "samples.flutter.io/platform_view", + &flutter::StandardMethodCodec::GetInstance()); + channel->SetMethodCallHandler([](const auto& call, auto result) { + int counter = std::get(*call.arguments()); + std::string msg = std::string("Pressed the button ") + + std::to_string(counter) + " times!"; + MessageBoxA(NULL, msg.c_str(), "Popup", MB_OK); + result->Success(flutter::EncodableValue(counter)); + }); +} + FlutterWindow::FlutterWindow(const flutter::DartProject& project) : project_(project) {} @@ -29,6 +57,7 @@ bool FlutterWindow::OnCreate() { return false; } RegisterPlugins(flutter_controller_->engine()); + RegisterMethodChannel(flutter_controller_->engine()); SetChildContent(flutter_controller_->view()->GetNativeWindow()); return true; }