dart_native
Write native code using Dart. This package liberates you from native code and low performance channel.
Still under development!!!
This is the blue part(DartNative Bridge) in the picture below:
📲 Requirement
DartNative Version | Requirements |
---|---|
0.3.0 | Flutter 1.20.0 (Dart 2.9.1) |
0.2.0 | Flutter 1.12.13 (Dart 2.7) |
🌟 Feature
- Support iOS & Android platform.
- Sync/Async channel with high performance.
- Generate Dart bridging code from native code.
- Automatic object marshalling between Dart and native.
🔮 Getting Started
Dart code:
// new Objective-C object.
RuntimeStub stub = RuntimeStub();
// Dart function will be converted to Objective-C block.
stub.fooBlock((NSObject a) {
print('hello block! ${a.toString()}');
return 101;
});
// support built-in structs.
CGRect rect = stub.fooCGRect(CGRect(4, 3, 2, 1));
print(rect);
Objective-C code:
typedef int(^BarBlock)(NSObject *a);
@interface RuntimeStub
- (CGRect)fooCGRect:(CGRect)rect;
- (void)fooBlock:(BarBlock)block;
@end
📚 Document
Readme
Blog
- 告别 Flutter Channel,调用 Native API 仅需一行代码!
- 如何实现一行命令自动生成 Flutter 插件
- 用 Dart 来写 Objective-C 代码
- 谈谈 dart_native 混合编程引擎的设计
- DartNative Memory Management: Object
- DartNative Memory Management: C++ Non-Object
- DartNative Struct
- 在 Flutter 中玩转 Objective-C Block
- Passing Out Parameter in DartNative
🐒 Q&A
Q: Failed to lookup symbol (dlsym(RTLD_DEFAULT, InitDartApiDL): symbol not found) on iOS archive.
There are two Workarounds:
- Use dynamic library: Add
use_frameworks!
in Podfile. - Select Target Runner -> Build Settings -> Strip Style -> change from "All Symbols" to "Non-Global Symbols"
❤️ Contributed
- If you need help or you'd like to ask a general question, open an issue.
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
👮🏻 License
DartNative is available under the BSD 3-Clause License. See the LICENSE file for more info.