-
创建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
相关推荐
嘟嘟叽1 天前
初学 flutter 环境变量配置iFlyCai1 天前
深入理解Flutter生命周期函数之StatefulWidget(一)sunly_1 天前
Flutter:photo_view图片预览功能Summer不秃1 天前
Flutter中sqflite的使用案例sunly_1 天前
Flutter:TweenAnimationBuilder自定义隐式动画AiFlutter1 天前
Flutter-Web首次加载时添加动画Allen Su2 天前
【Flutter 问题系列第 84 篇】如何清除指定网络图片的缓存sunly_2 天前
Flutter:key的作用原理(LocalKey ,GlobalKey)AiFlutter2 天前
Flutter-flutter_blue_plus打包后无法进行设备扫描fifiAmx2 天前
Flutter 扫描二维码