-
创建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, ), ], ), ), ), ), ); }
}
-
效果展示
鸿蒙harmonyos next flutter混合开发之开发FFI plugin
helloxmg2024-10-07 9:23
相关推荐
lazy_yun13 小时前
flutter插件开发-ios火柴就是我14 小时前
flame forge2d 实现随机小怪以及飞镖射中爆炸机器瓦力14 小时前
Flutter应用开发:返回列表刷新并保持原始操作位置弱水三千只取一瓢编号88090818 小时前
Flutter路由工具类RouteUtils,可二次开发,拿来即用迷雾漫步者1 天前
flutter组件————Row和Columntmacfrank1 天前
Flutter 插件开发入门任聪聪2 天前
Flutter 调试环境下浏览器网络请求跨域问题解决方案用户26830368955972 天前
记录一次flutter项目更新到3.27kirk_wang3 天前
Flutter适配HarmonyOS实践Jalor3 天前
HarmonyOS NEXT | 一文搞懂 华为账号登录(获取UnionID/OpenID)