Unverified Commit 97ab92ee authored by Hossein Yousefi's avatar Hossein Yousefi Committed by GitHub

Modify `plugin_ffi` and `package_ffi` template (#143376)

* Use `dart run` instead of `flutter pub run` in the documentation as it is now deprecated.
* Use `int64_t` instead of `intptr_t` for `sum` examples.
parent dde76f49
......@@ -31,7 +31,7 @@ Bundling is done by Flutter based on the output from `build.dart`.
To use the native code, bindings in Dart are needed.
To avoid writing these by hand, they are generated from the header file
(`src/{{projectName}}.h`) by `package:ffigen`.
Regenerate the bindings by running `flutter pub run ffigen --config ffigen.yaml`.
Regenerate the bindings by running `dart run ffigen --config ffigen.yaml`.
## Invoking native code
......
# Run with `flutter pub run ffigen --config ffigen.yaml`.
# Run with `dart run ffigen --config ffigen.yaml`.
name: {{pluginDartClass}}Bindings
description: |
Bindings for `src/{{projectName}}.h`.
Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`.
Regenerate bindings with `dart run ffigen --config ffigen.yaml`.
output: 'lib/{{projectName}}_bindings_generated.dart'
headers:
entry-points:
......
......@@ -73,7 +73,7 @@ The native build systems that are invoked by FFI (and method channel) plugins ar
To use the native code, bindings in Dart are needed.
To avoid writing these by hand, they are generated from the header file
(`src/{{projectName}}.h`) by `package:ffigen`.
Regenerate the bindings by running `flutter pub run ffigen --config ffigen.yaml`.
Regenerate the bindings by running `dart run ffigen --config ffigen.yaml`.
## Invoking native code
......
# Run with `flutter pub run ffigen --config ffigen.yaml`.
# Run with `dart run ffigen --config ffigen.yaml`.
name: {{pluginDartClass}}Bindings
description: |
Bindings for `src/{{projectName}}.h`.
Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`.
Regenerate bindings with `dart run ffigen --config ffigen.yaml`.
output: 'lib/{{projectName}}_bindings_generated.dart'
headers:
entry-points:
......
......@@ -10,7 +10,7 @@ import 'dart:ffi' as ffi;
/// Bindings for `src/{{projectName}}.h`.
///
/// Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`.
/// Regenerate bindings with `dart run ffigen --config ffigen.yaml`.
///
class {{pluginDartClass}}Bindings {
/// Holds the symbol lookup function.
......@@ -43,7 +43,7 @@ class {{pluginDartClass}}Bindings {
}
late final _sumPtr =
_lookup<ffi.NativeFunction<ffi.IntPtr Function(ffi.IntPtr, ffi.IntPtr)>>(
_lookup<ffi.NativeFunction<ffi.Int Function(ffi.Int, ffi.Int)>>(
'sum');
late final _sum = _sumPtr.asFunction<int Function(int, int)>();
......@@ -63,7 +63,7 @@ class {{pluginDartClass}}Bindings {
}
late final _sum_long_runningPtr =
_lookup<ffi.NativeFunction<ffi.IntPtr Function(ffi.IntPtr, ffi.IntPtr)>>(
_lookup<ffi.NativeFunction<ffi.Int Function(ffi.Int, ffi.Int)>>(
'sum_long_running');
late final _sum_long_running =
_sum_long_runningPtr.asFunction<int Function(int, int)>();
......
......@@ -5,14 +5,14 @@
// For very short-lived functions, it is fine to call them on the main isolate.
// They will block the Dart execution while running the native function, so
// only do this for native functions which are guaranteed to be short-lived.
FFI_PLUGIN_EXPORT intptr_t sum(intptr_t a, intptr_t b) { return a + b; }
FFI_PLUGIN_EXPORT int sum(int a, int b) { return a + b; }
// A longer-lived native function, which occupies the thread calling it.
//
// Do not call these kind of native functions in the main isolate. They will
// block Dart execution. This will cause dropped frames in Flutter applications.
// Instead, call these native functions on a separate isolate.
FFI_PLUGIN_EXPORT intptr_t sum_long_running(intptr_t a, intptr_t b) {
FFI_PLUGIN_EXPORT int sum_long_running(int a, int b) {
// Simulate work.
#if _WIN32
Sleep(5000);
......
......@@ -20,11 +20,11 @@
// For very short-lived functions, it is fine to call them on the main isolate.
// They will block the Dart execution while running the native function, so
// only do this for native functions which are guaranteed to be short-lived.
FFI_PLUGIN_EXPORT intptr_t sum(intptr_t a, intptr_t b);
FFI_PLUGIN_EXPORT int sum(int a, int b);
// A longer lived native function, which occupies the thread calling it.
//
// Do not call these kind of native functions in the main isolate. They will
// block Dart execution. This will cause dropped frames in Flutter applications.
// Instead, call these native functions on a separate isolate.
FFI_PLUGIN_EXPORT intptr_t sum_long_running(intptr_t a, intptr_t b);
FFI_PLUGIN_EXPORT int sum_long_running(int a, int b);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment