Add windows implementation to platform_view example (#109715)
* Add Windows platform view example * Add new tests for Windows desktop * Add Windows platform view * Use const constructors (linux analyze)\ * Fix spelling/format * Clean up code * Remove default case
This commit is contained in:
parent
9da693e3fa
commit
9eca99b8df
@ -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<MyHomePage> {
|
||||
});
|
||||
}
|
||||
|
||||
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<void> _launchPlatformCount() async {
|
||||
final int? platformCounter =
|
||||
await _methodChannel.invokeMethod('switchView', _counter);
|
||||
@ -76,9 +91,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -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}"
|
||||
|
@ -4,10 +4,38 @@
|
||||
|
||||
#include "flutter_window.h"
|
||||
|
||||
#include <WinUser.h>
|
||||
#include <flutter/flutter_engine.h>
|
||||
#include <flutter/method_channel.h>
|
||||
#include <flutter/plugin_registrar_windows.h>
|
||||
#include <flutter/standard_method_codec.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#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<flutter::PluginRegistrarWindows>(plugin_registrar_ref);
|
||||
auto channel =
|
||||
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
|
||||
registrar->messenger(), "samples.flutter.io/platform_view",
|
||||
&flutter::StandardMethodCodec::GetInstance());
|
||||
channel->SetMethodCallHandler([](const auto& call, auto result) {
|
||||
int counter = std::get<int32_t>(*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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user