当前位置: 首页 > article >正文

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

  • 创建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});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int sumResult = 0;
  int sumAsyncResult = 0;

  @override
  void initState() {
    super.initState();
    sumResult = summation.sum(1, 2);
     summation.sumAsync(3, 4).then((value) {
       sumAsyncResult = value;
       setState(() {

       });
     });
  }

  @override
  Widget 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.kler.cn/news/341659.html

相关文章:

  • 量化交易与基础投资工具介绍
  • TIM的PWM模式
  • Java使用注解进行参数校验
  • 【每天学点AI】大模型如何做情感分类?BERT是如何做情感分类的?
  • 等保测评是什么?为什么要做等保测评?
  • 技术分享 —— JMeter接口与性能测试实战!
  • 探索一机两用号召是否和源代码保密冲突
  • 智能听诊器:宠物健康教育的创新工具
  • 国产工具链GCKontrol-GCAir助力控制律开发快速验证
  • rust使用tokio
  • SPIE出版-EI会议-人机交互 虚拟现实 <<< 11月杭州
  • linux 重置root密码
  • 如何一键将数据库表导出为Excel,并且列名为中文注释
  • 【笔记】6.2 玻璃的成型
  • 文献阅读Prov-GigaPath模型--相关知识点罗列
  • 【React】setState 的同步异步问题
  • 汽车软件设计时容易忽略的点 -- 观ETAS Webinar有感
  • Windows系统安装Fooocus结合内网穿透实现公网环境远程生成AI图片
  • 『Mysql进阶』Mysql explain详解(五)
  • jQuery基础