CodeAsset class final
A code asset which respects the native application binary interface (ABI).
Typical languages which produce code assets that respect the native ABI
include C, C++ (with extern "C"
), Rust (with extern "C"
), and a subset
of language features of Objective-C.
Native code assets can be accessed at runtime through native external functions via their asset id:
import 'dart:ffi';
void main() {
final result = add(14, 28);
print(result);
}
@Native<Int Function(Int, Int)>(assetId: 'package:my_package/add.dart')
external int add(int a, int b);
There are several types of native code assets:
- Assets which designate symbols present in the target system (DynamicLoadingSystem), process (LookupInProcess), or executable (LookupInExecutable). These assets do not have a file.
- Dynamic libraries bundled into the application (DynamicLoadingBundled). These assets must provide a file to be bundled.
An application is compiled to run on a specific target os and architecture. Different targets require different assets, so the package developer must specify which asset to bundle for which target.
An asset has different ways of being accessible in the final application. It is either brought in "manually" by having the package developer specify a file path of the asset on the current system, it can be part of the Dart or Flutter SDK (LookupInProcess), or it can be already present in the target system (DynamicLoadingSystem). If the asset is bundled "manually", the Dart or Flutter SDK will take care of copying the asset file from its specified location on the current system into the application bundle.
Constructors
- CodeAsset({required String package, required String name, required LinkMode linkMode, required OS os, Uri? file, Architecture? architecture})
- Constructs a native code asset.
- CodeAsset.fromEncoded(EncodedAsset asset)
-
factory
Properties
- architecture → Architecture?
-
The architecture this asset can run on.
final
- file → Uri?
-
The file to be bundled with the Dart or Flutter application.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- id → String
-
The id of this code asset.
final
- linkMode → LinkMode
-
The link mode for this native code.
final
- os → OS
-
The operating system this asset can run on.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
copyWith(
{LinkMode? linkMode, String? id, OS? os, Architecture? architecture, Uri? file}) → CodeAsset -
encode(
) → EncodedAsset -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override