chore: generate template (#17)

This commit is contained in:
github-actions[bot]
2022-04-11 14:18:19 -05:00
committed by GitHub
parent 5baf0dfa61
commit 699457e663
249 changed files with 932 additions and 932 deletions

View File

@@ -0,0 +1,17 @@
flutter/
# Visual Studio user-specific files.
*.suo
*.user
*.userosscache
*.sln.docstates
# Visual Studio build-related files.
x64/
x86/
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

View File

@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.14)
set(PROJECT_NAME "{{project_name.snakeCase()}}_windows")
project(${PROJECT_NAME} LANGUAGES CXX)
set(PLUGIN_NAME "${PROJECT_NAME}_plugin")
add_library(${PLUGIN_NAME} SHARED
"{{project_name.snakeCase()}}_windows_plugin.cpp"
"include/{{project_name.snakeCase()}}_windows/{{project_name.snakeCase()}}_windows.h"
)
apply_standard_settings(${PLUGIN_NAME})
set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden)
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
target_include_directories(${PLUGIN_NAME} INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
# List of absolute paths to libraries that should be bundled with the plugin
set({{project_name.snakeCase()}}_bundled_libraries
""
PARENT_SCOPE
)

View File

@@ -0,0 +1,23 @@
#ifndef FLUTTER_PLUGIN_MY_PLUGIN_WINDOWS_PLUGIN_H_
#define FLUTTER_PLUGIN_MY_PLUGIN_WINDOWS_PLUGIN_H_
#include <flutter_plugin_registrar.h>
#ifdef FLUTTER_PLUGIN_IMPL
#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport)
#else
#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport)
#endif
#if defined(__cplusplus)
extern "C" {
#endif
FLUTTER_PLUGIN_EXPORT void {{project_name.pascalCase()}}WindowsRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar);
#if defined(__cplusplus)
} // extern "C"
#endif
#endif // FLUTTER_PLUGIN_MY_PLUGIN_WINDOWS_PLUGIN_H_

View File

@@ -0,0 +1,72 @@
#include "include/{{project_name.snakeCase()}}_windows/{{project_name.snakeCase()}}_windows.h"
// This must be included before many other Windows headers.
#include <windows.h>
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar_windows.h>
#include <flutter/standard_method_codec.h>
#include <map>
#include <memory>
namespace {
using flutter::EncodableValue;
class {{project_name.pascalCase()}}Windows : public flutter::Plugin {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
{{project_name.pascalCase()}}Windows();
virtual ~{{project_name.pascalCase()}}Windows();
private:
// Called when a method is called on this plugin's channel from Dart.
void HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue> &method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
};
// static
void {{project_name.pascalCase()}}Windows::RegisterWithRegistrar(
flutter::PluginRegistrarWindows *registrar) {
auto channel =
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
registrar->messenger(), "{{project_name.snakeCase()}}_windows",
&flutter::StandardMethodCodec::GetInstance());
auto plugin = std::make_unique<{{project_name.pascalCase()}}Windows>();
channel->SetMethodCallHandler(
[plugin_pointer = plugin.get()](const auto &call, auto result) {
plugin_pointer->HandleMethodCall(call, std::move(result));
});
registrar->AddPlugin(std::move(plugin));
}
{{project_name.pascalCase()}}Windows::{{project_name.pascalCase()}}Windows() {}
{{project_name.pascalCase()}}Windows::~{{project_name.pascalCase()}}Windows() {}
void {{project_name.pascalCase()}}Windows::HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue> &method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
if (method_call.method_name().compare("getPlatformName") == 0) {
result->Success(EncodableValue("Windows"));
}
else {
result->NotImplemented();
}
}
} // namespace
void {{project_name.pascalCase()}}WindowsRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar) {
{{project_name.pascalCase()}}Windows::RegisterWithRegistrar(
flutter::PluginRegistrarManager::GetInstance()
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
}