1. 创建插件
mkdir win_test && cd win_test
flutter create -t plugin --platforms windows ./
  1. 找到win_test\example\build\windows\plugins\win_test\win_test_plugin.sln使用vs打开编辑

  2. 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 );

flutter 使用vs编辑windows插件的更多相关文章

  1. 在 Flutter 中使用 TensorFlow Lite 插件实现文字分类

    如果您希望能有一种简单.高效且灵活的方式把 TensorFlow 模型集成到 Flutter 应用里,那请您一定不要错过我们今天介绍的这个全新插件 tflite_flutter.这个插件的开发者是 G ...

  2. 谷歌发布Flutter Alpha:支持Windows

    老孟导读:Windows来了,Mac.Linux.Web还远吗? 本文翻译自https://medium.com/flutter/announcing-flutter-windows-alpha-33 ...

  3. 咏南跨平台中间件支持LINUX和WINDOWS插件架构

    咏南跨平台中间件支持LINUX和WINDOWS插件架构

  4. Flutter Toast消息提示框插件

    Flutter Toast消息提示框插件 在开发flutter项目中,想必大家肯定会用到toast消息提示,说到这里, 大家肯定会想到https://pub.dev/ 插件库, 但是插件市场上有太多类 ...

  5. flutter 使用Android studio编辑kt插件

    使用android studio打开/example/android 文件即可

  6. win7系统下flutter环境搭建+AndroidStudio编译插件

    flutter学习网址:https://flutter-io.cn/ ----------------------------------------------------------------- ...

  7. JavaScript- jquery easyui 可编辑表格插件 easyui.editgrid

    最近项目前端使用 jquery+easyui来做,用了几个月,觉得easyui是一个很不错的开源前端UI框架, 虽然偶尔会遇到一些小问题,但是凭借多年前端开发的实力积累 都一一解决了,其中比较典型的就 ...

  8. jQuery插件之jquery editable plugin--点击编辑文字插件

    jeditable是一个jquery插件,它的优点是可以就地编辑,并且提交到服务器处理,是一个不可多得的就地编辑插件.(注: 就地编辑,也有称即时编辑?一般的流程是这样的,当用户点击网页上的文字时,该 ...

  9. Jeditable 点击编辑文字插件

    Jeditable - jQuery就地编辑插件使用   jeditable是一个jquery插件,它的优点是可以就地编辑,并且提交到服务器处理,是一个不可多得的就地编辑插件.(注: 就地编辑,也有称 ...

随机推荐

  1. C# 实现一个基于值相等性比较的字典

    C# 实现一个基于值相等性比较的字典 Intro 今天在项目里遇到一个需求,大概是这样的我要比较两个 JSON 字符串是不是相等,JSON 字符串其实是一个 Dictionary<string, ...

  2. MTO1804无刷电机引发的悲惨经历之二:电调固件刷新与优化

    前言 原创文章,转载引用请务必注明链接,水平有限,如有疏漏,欢迎指正. 书接上回,我们总算是基本确认了黑衣神秘电调的身份,本文就尝试对电调固件进行一番设置,来个免费优化. 1.刷新固件 关于电调的固件 ...

  3. Java实现windows,linux服务器word,excel转为PDF;aspose-words,Documents4j

    Java实现windows,linux服务器word,excel转为PDF:aspose-words,Documents4j 一.通过aspose-words将word,Excel文档转为PDF 1. ...

  4. hibernate+spring+tomcat启动报错Not supported by BasicDataSource

    最近使用hibernate+spring+jsp的小项目制作过程中出现一些错误,例如: java.lang.UnsupportedOperationException: Not supported b ...

  5. Spring cloud-Bus (消息总线)

    <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring ...

  6. linux系统命令(调试命令)(nmtui,ip a、ss、ps、uptime、top、lsof、grep,iotop、iftop)

    本章命令 0 1 2 3 4 5 6 7 8 9 10 nmtui ip a ss ps uptime top lsof grep iotop iftop tsar nmtui 图形化管理网卡命令 依 ...

  7. Nacos服务心跳和健康检查源码介绍

    服务心跳 Nacos Client会维护一个定时任务通过持续调用服务端的接口更新心跳时间,保证自己处于存活状态,防止服务端将服务剔除,Nacos默认5秒向服务端发送一次,通过请求服务端接口/insta ...

  8. 【函数分享】每日PHP函数分享(2021-2-6)

    array_combine - 创建一个数组,用一个数组的值作为其键名,另一个数组的值作为其值 说明: array_combine ( array $keys , array $values ) : ...

  9. Eclipse中配置Junit

    在要使用Junit的project名上,点击properties-->Java Build Path-->Libraries,点击Add Library 选择Junit 选择Junit 4 ...

  10. Educational Codeforces Round 21

    Educational Codeforces Round 21  A. Lucky Year 个位数直接输出\(1\) 否则,假设\(n\)十进制最高位的值为\(s\),答案就是\(s-(n\mod ...