text
stringlengths
1
474
at <path_to_flutter_sdk>/bin/cache/artifacts/engine/ios/extension_safe/Flutter.xcframework.Drag and drop the Flutter.xcframework file into your
share extension’s frameworks and libraries list.
Make sure the embed column says “Embed & Sign”.Open the Flutter app project settings in Xcode
to share build configurations.(Optional) Replace any storyboard files with an extension class, if needed.Embed the FlutterViewController as described in
Adding a Flutter Screen. For example, you can display a
specific route in your Flutter app within a share extension.<topic_end>
<topic_start>
Test extensions
Testing extensions on simulators and physical devices
have slightly different procedures.<topic_end>
<topic_start>
Test on a simulator
<topic_end>
<topic_start>
Test on a physical device
You can use the following procedure or the
Testing on simulators instructions
to test on physical devices.<topic_end>
<topic_start>
Tutorials
For step-by-step instruction for using app
extensions with your Flutter iOS app, check out the
Adding a Home Screen Widget to your Flutter app
codelab.
<topic_end>
<topic_start>Binding to native iOS code using dart:ffi
Flutter mobile and desktop apps can use the
dart:ffi library to call native C APIs.
FFI stands for foreign function interface.
Other terms for similar functionality include
native interface and language bindings.info Note
This page describes using the dart:ffi library
in iOS apps. For information on Android, see
Binding to native Android code using dart:ffi.
For information in macOS, see
Binding to native macOS code using dart:ffi.
This feature is not yet supported for web plugins.Before your library or program can use the FFI library
to bind to native code, you must ensure that the
native code is loaded and its symbols are visible to Dart.
This page focuses on compiling, packaging,
and loading iOS native code within a Flutter plugin or app.This tutorial demonstrates how to bundle C/C++
sources in a Flutter plugin and bind to them using
the Dart FFI library on iOS.
In this walkthrough, you’ll create a C function
that implements 32-bit addition and then
exposes it through a Dart plugin named “native_add”.<topic_end>
<topic_start>
Dynamic vs static linking
A native library can be linked into an app either
dynamically or statically. A statically linked library
is embedded into the app’s executable image,
and is loaded when the app starts.Symbols from a statically linked library can be
loaded using DynamicLibrary.executable or
DynamicLibrary.process.A dynamically linked library, by contrast, is distributed
in a separate file or folder within the app,
and loaded on-demand. On iOS, the dynamically linked
library is distributed as a .framework folder.A dynamically linked library can be loaded into
Dart using DynamicLibrary.open.API documentation is available from the Dart dev channel:
Dart API reference documentation.<topic_end>
<topic_start>
Create an FFI plugin
To create an FFI plugin called “native_add”,
do the following:info Note
You can exclude platforms from --platforms that you don’t want
to build to. However, you need to include the platform of
the device you are testing on.This will create a plugin with C/C++ sources in native_add/src.
These sources are built by the native build files in the various
os build folders.The FFI library can only bind against C symbols,
so in C++ these symbols are marked extern "C".You should also add attributes to indicate that the
symbols are referenced from Dart,
to prevent the linker from discarding the symbols
during link-time optimization.
__attribute__((visibility("default"))) __attribute__((used)).On iOS, the native_add/ios/native_add.podspec links the code.The native code is invoked from dart in lib/native_add_bindings_generated.dart.The bindings are generated with package:ffigen.<topic_end>
<topic_start>
Other use cases
<topic_end>
<topic_start>
iOS and macOS
Dynamically linked libraries are automatically loaded by
the dynamic linker when the app starts. Their constituent
symbols can be resolved using DynamicLibrary.process.
You can also get a handle to the library with
DynamicLibrary.open to restrict the scope of
symbol resolution, but it’s unclear how Apple’s
review process handles this.Symbols statically linked into the application binary
can be resolved using DynamicLibrary.executable or
DynamicLibrary.process.<topic_end>
<topic_start>Platform library
To link against a platform library,
use the following instructions:<topic_end>
<topic_start>First-party library
A first-party native library can be included either
as source or as a (signed) .framework file.
It’s probably possible to include statically linked
archives as well, but it requires testing.<topic_end>
<topic_start>Source code
To link directly to source code,
use the following instructions:Add the following prefix to the
exported symbol declarations to ensure they
are visible to Dart:C/C++/Objective-CSwift<topic_end>