displays the Flutter application UI and starts the Flutter engine. You would use FlutterActivity when you want to show Flutter UI within an Android native application. FlutterPlugin FlutterPlugin is an interface for communication between Flutter and the native platform (e.g., Android, iOS). You would implement FlutterPlugin when you want to call native APIs or handle specific events in a Flutter application. 15
function interface) → C • FFIgen • JNI (Java Native Interface) → Java & Kotlin • JNIgen (Java Native Interface) • and other bridges Interoperability 17 Methods : How to
• Think functionality first, then APIs • Avoid platform-specific API methods • Avoid supporting only one platform • Make your plugin easy to navigate and test • Avoid writing static (or global) methods @sourece : https://medium.com/flutter/writing-a-good-flutter-plugin-1a561b986c9c
started, a DartExecutor cannot be stopped. The associated Dart code will execute until it completes, or until the FlutterEngine that owns this DartExecutor is destroyed. • Creates a FlutterEngine in this group and run its DartExecutor with a default entrypoint of the "main" function in the "lib/main.dart" file. DartExecutor 27
Flutter and the host platform type-safe, easier, and faster. • Pigeon removes the necessity to manage strings across multiple platforms and languages. • It also improves efficiency over common method channel patterns. • Most importantly though, it removes the need to write custom platform channel code, since pigeon generates it for you. Code generator tool Pigeon 58
the host platform. • When you want to call the host platform from Flutter. @FlutterApi • @FlutterApi() for procedures that are defined in Dart. • When you want to call a Flutter app from the host platform. 68 / Pigeon
function interface. • Dart mobile, command-line, and server apps running on the Dart Native platform can use the dart:ffi library to call native C APIs, and to read, write, allocate, and deallocate native memory. • ffigen only supports parsing C headers, not C++ headers.
// FIBONACCI_H fibonacci.h @Source https://en.wikipedia.org/wiki/Fibonacci_sequence By Romain - Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=114415511
{ if n <= 0 { return 0; } else if n == 1 { return 1; } else { let mut a = 0; let mut b = 1; let mut c = 0; for _ in 2..=n { c = a + b; a = b; b = c; } return c; } cargo build --release --target=[target] Android cargo ndk -t [target] -o ./jniLibs build --release • arm64-v8a • armeabi-v7a • x86 • x86_64
Function(int); final Fibonacci fibonacci = _dylib .lookup<ffi.NativeFunction<FibonacciFunc>>('fibonacci') .asFunction(); int n = 10; int result = fibonacci(n);