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. 洛谷P4981

    Description 给定 n 个点,组成一棵树,有多少种组合方法: Analysis 首先,结合题目简化意义和这句话 最多可能存在多少种父子关系 我们可以知道当且仅当有至少一个节点的儿子不同时称他 ...

  2. 洛谷P3850 书架

    题目描述 Knuth先生家里有个精致的书架,书架上有N本书,如今他想学到更多的知识,于是又买来了M本不同的新书.现在他要把新买的书依次插入到书架中,他已经把每本书要插入的位置标记好了,并且相应的将它们 ...

  3. Java 执行过程中的内存模型

    一.前言 本文的主要工作:尝试以时间顺序追踪一遍 Java 执行的整个过程,以及展示 JVM 中内存模型的相应变化. 本文的主要目的:希望能够通过 Java 执行过程的冰山一角,增进对编程语言工作原理 ...

  4. Atlas 2.1.0 实践(4)—— 权限控制

    Atlas的权限控制非常的丰富,本文将进行其支持的各种权限控制的介绍. 在atlas-application.properties配置文件中,可以设置不同权限的开关. atlas.authentica ...

  5. linux c驴杂记

    C语言标准库中包含了各种用于处理错误的函数和宏.1.assert( ) 宏 #include<assert.h>void assert( int expression );可用于诊断程序b ...

  6. python模块----os模块 (操作系统接口模块)

    os模块提供一种使用与操作系统相关的功能的便捷式途径. 一定要使用 import os 而不是 from os import * .这将避免内建的 open() 函数被 os.open() 隐式替换掉 ...

  7. 常用的trigger表达式

    1.Name:Incoming traffic on interface {#SNMPVALUE} is greater than 300Mb, now is {ITEM.VALUE} Express ...

  8. hdu 6268 Master of Subgraph(点分治+bitset)

    You are given a tree with n nodes. The weight of the i-th node is wi. Given a positive integer m, no ...

  9. HDU4467 Graph【轻重点维护】

    HDU4467 Graph 题意: 给出一张染色图,\(n\)个点每个点是黑色或者白色,\(m\)条带权边,\(q\)次操作,有两种操作: 改变一个点的颜色 问所有边中两个端点的颜色为给定情况的边权和 ...

  10. uva10891 Game of Sum(博弈+区间dp+优化)

    题目:点击打开链接 题意:两个人做游戏,共有n个数,每个人可以任选一端取任意多连续的数,问两个人都想拿最多的情况下,先手最多比后手多拿多少分数. 思路:这题一开始想到的是用dp[i][j]表示区间[i ...