鸿蒙harmonyos next flutter混合开发之开发FFI plugin

server/2024/10/11 3:03:52/
  • 创建FFI plugin summation,默认创建的FFI plugin是求两个数的和
flutter create --template=plugin_ffi summation --platforms=android,ios,ohos
  • 创建my_application
flutter create --org com.example my_application
  • 在my_application项目中文件pubspec.yaml引用summation
  summation:path: /Users/administrator/Desktop/workspace/summation
  • my_application中调用summation
import 'package:flutter/material.dart';
import 'package:summation/summation.dart' as summation;void main() {runApp(const MyApp());
}class MyApp extends StatefulWidget {const MyApp({super.key});@overrideState<MyApp> createState() => _MyAppState();
}class _MyAppState extends State<MyApp> {int sumResult = 0;int sumAsyncResult = 0;@overridevoid initState() {super.initState();sumResult = summation.sum(1, 2);summation.sumAsync(3, 4).then((value) {sumAsyncResult = value;setState(() {});});}@overrideWidget build(BuildContext context) {const textStyle = TextStyle(fontSize: 25);const spacerSmall = SizedBox(height: 10);return MaterialApp(home: Scaffold(appBar: AppBar(title: const Text('my_application调用ffiplugin'),),body: SingleChildScrollView(child: Container(padding: const EdgeInsets.all(10),child: Column(children: [Text('同步求和sum(1, 2) = $sumResult',style: textStyle,textAlign: TextAlign.center,),spacerSmall,Text('异步求和sum(3, 4) = $sumAsyncResult',style: textStyle,textAlign: TextAlign.center,),],),),),),);}
}
  • 效果展示


http://www.ppmy.cn/server/129911.html

相关文章

自由学习记录

约束的泛型通配符? Java中的泛型 xiaomi和byd都继承了car&#xff0c;但是只是这两个类是car的子类而已&#xff0c;而arraylist<xiaomi> ,arraylist<byd> 两个没有半毛钱继承关系 所以传入的参数整体&#xff0c;是car的list变形&#xff0c;里面的确都能存car…

Git基本操作与分支

一、操作入门 先看大屏幕&#xff1a;先背过 再来操作 初始化 刚入门的小朋友可能出现这种问题&#xff1a; 原因是&#xff1a;需要自己创建一个记事本文件 add的作用是添加指定文件到暂存区。 commit是提交暂存区到仓库区&#xff0c;此处的仓库是本地仓库&#xff0c;本…

Word页眉内容自动填充为章节标题

Word页眉内容自动填充为章节标题 在写毕业论文的过程中&#xff0c;通常要求将页眉设置为章节标题&#xff0c;例如这样 通常&#xff0c;页眉内容我们都是手敲上去的&#xff0c;其实在Word中可以设置为自动引用章节标题&#xff0c;以下为设置方法&#xff0c;仅供参考&…

【华为HCIP实战课程七】OSPF邻居关系排错MTU问题,网络工程师

一、MTU MUT默认1500,最大传输单元,一致性检测 [R3-GigabitEthernet0/0/1]mtu 1503//更改R3的MTU为1503 查看R3和SW1之间的OSPF邻居关系正常: 默认华为设备没有开启MTU一致性检测! [R3-GigabitEthernet0/0/1]ospf mtu-enable //手动开启MTU检测 [SW1-Vlanif30]ospf mtu…

JSONL 文件的检查和修订器

下面是一个JSONL 文件的检查和修订器,代码如下: import json import tkinter as tk from tkinter import filedialog, messageboxdef check_jsonl_file(input_file, log_file, output_file=None):errors = []valid_lines = []with open(input_file, r, encoding=utf-8) as in…

360 度评估的优缺点

什么是 360 度评估&#xff1f; “360 度评估是一种人才培养工具&#xff0c;用于为接受者提供全方位的反馈&#xff0c;这通常包括来自他们直接下属的向上反馈、来自与他们密切合作的同事的反馈&#xff0c;以及来自他们经理的向下反馈。” 通常&#xff0c;360 度评估是匿名…

JavaScript中的with语句详解

参考链接&#xff1a;https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/with 注&#xff1a;该属性已被W3C废弃&#xff0c;请谨慎使用。 作用 当我们想快速访问一个对象上的属性时&#xff0c;可以简化代码 语法 with (expression) statem…

SQL自学:什么是SQL的聚集函数,如何利用它们汇总表的数据

在 SQL&#xff08;Structured Query Language&#xff0c;结构化查询语言&#xff09;中&#xff0c;聚集函数也称为聚合函数&#xff0c;是对一组值进行计算并返回单一值的函数。 一、常见的聚集函数及功能 1. AVG()&#xff1a;用于计算某一列的平均值。 例如&#xff0c;…