address_ position
Details about the 'address_position' diagnostic produced by the Dart analyzer.
The '.address' expression can only be used as argument to a leaf native external call.
Description
#
The analyzer produces this diagnostic when the
.address getter is used in a context other than
as an argument to a native external call that is marked as a
leaf call (isLeaf: true).
Example
#
The following code produces this diagnostic because
.address is used incorrectly:
import 'dart:ffi';
import 'dart:typed_data';
@Native<Void Function(Pointer<Uint8>)>()
external void nonLeafCall(Pointer<Uint8> ptr);
void main() {
final data = Uint8List(10);
// Incorrect: Using '.address' as an argument to a non-leaf call.
nonLeafCall(data.address);
}
Common fixes
#
Ensure that the .address expression is used
directly as an argument to a native external call that is
annotated with @Native(...) and has
isLeaf: true set in its annotation.
import 'dart:ffi';
import 'dart:typed_data';
@Native<Void Function(Pointer<Uint8>)>(isLeaf: true)
external void leafCall(Pointer<Uint8> ptr);
void main() {
final data = Uint8List(10);
// Correct: Using .address directly as an argument to a leaf call.
leafCall(data.address);
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.