flutter 使用vs编辑windows插件
2023-09-14 08:58:44 时间
- 创建插件
mkdir win_test && cd win_test
flutter create -t plugin --platforms windows ./
-
找到
win_test\example\build\windows\plugins\win_test\win_test_plugin.sln
使用vs打开编辑 -
在
win_test\lib\win_test.dart
中编写Dart Api
一个函数示例
win_test.dart:
class WinTest {
static const MethodChannel _channel = const MethodChannel('win_test');
///
///## Example
///```dart
///print( await WinTest.hello("hello world", "msg", 0) );
///```
///
static Future<int> hello(String content, String title, int uType) async {
return await _channel.invokeMethod('hello', [content, title, uType]);
}
}
win_test_plugin.cpp:
#include <iostream>
using namespace std;
void WinTestPlugin::HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue> &method_call,
unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
if ( method_call.method_name().compare("hello") == 0 )
{
const auto* arguments = get_if<flutter::EncodableList>(method_call.arguments());
if (!arguments)
{
result->Error(0);
return;
}
auto lpText = arguments->at(0);
auto lpCaption = arguments->at(1);
auto uType = arguments->at(2);
result->Success(
MessageBoxA(0, get<string>(lpText).c_str(), get<string>(lpCaption).c_str(), get<int>(uType))
);
}
result->NotImplemented();
}
处理单个参数
_channel.invokeMethod('hello', 10);
auto* uFlags = get_if<int>(mc.arguments());
发送map返回list
print(await _channel.invokeMethod(
'hello',
{'a': 1, 'b': 'hello world'},
)); // [1, hello world]
auto* arguments = get_if<flutter::EncodableMap>(method_call.arguments());
if (!arguments)
{
result->Error("arguments error");
return;
}
auto* a = get_if<int>(&(arguments->find(flutter::EncodableValue("a"))->second));
auto* b = get_if<string>(&(arguments->find(flutter::EncodableValue("b"))->second));
auto r = flutter::EncodableList();
r.push_back( *a );
r.push_back( *b );
result->Success(r);
返回Map
print(
await _channel.invokeMethod(
'hello',
{'a': 1, 'b': 'hello world'},
)
); // {a_v: 1, b_v: hello world}
auto* arguments = get_if<flutter::EncodableMap>(method_call.arguments());
if (!arguments)
{
result->Error("arguments error");
return;
}
auto* a = get_if<int>(&(arguments->find(flutter::EncodableValue("a"))->second));
auto* b = get_if<string>(&(arguments->find(flutter::EncodableValue("b"))->second));
auto r = flutter::EncodableMap::map();
r.insert(pair<flutter::EncodableValue, flutter::EncodableValue>(flutter::EncodableValue("a_v"), *a));
r.insert(pair<flutter::EncodableValue, flutter::EncodableValue>(flutter::EncodableValue("b_v"), flutter::EncodableValue(b->c_str())));
result->Success( r );
相关文章
- Windows 老是弹出要自动拨号连接怎么办
- VS连接Windows Mobile模拟器
- 博客园配置windows live writer,实现本地代码高亮
- windows server 2008使用第三方软件搭建FTP服务器
- windows 远程桌面命令 mstsc
- MFC Windows 程序设计[230]之驱动盘列表拾取器(附源码)
- Windows Server AppFabric与WCF
- Windows下使用QT+OpenCV完成人脸检测(获取摄像头的数据进行检测)
- WINDOWS.H already included. MFC apps must not #include <Windows.h>
- Chromium学习笔记:程序启动入口分析(Windows)
- chromium在windows上的编译 构建 Checking out and Building Chromium for Windows
- C语言使用技巧(二十一):VS CODE在windows下配置CMAKE编译环境【实现C/C++可同时在一个文件夹下编译】
- iscsi target windows和linux连接 iscsi在线扩容
- GDI+入门——带你走进Windows图形的世界
- Windows git 初始设置
- 内网渗透(二十一)之Windows协议认证和密码抓取-Golden Ticket黄金票据制作原理及利用方式
- C# 编写Windows Service(windows服务程序)
- Windows命令行使用FTP——windows下自带ftp命令
- 一文吃透 VS Code+Git 操作(vs code中git的相关配置与使用)
- 7-6Keyed vs Non-Keyed Windows
- 完美解决在Windows下Vs Code编译不同C函数之间的调用问题