variable_ length_ array_ not_ last
Variable length 'Array's must only occur as the last field of Structs.
Description
#
The analyzer produces this diagnostic when a variable length inline
Array
is not the last member of a
Struct
.
For more information about FFI, see C interop using dart:ffi.
Example
#
The following code produces this diagnostic because the field
a0
has a
type with three nested arrays, but only two dimensions are given in the
Array
annotation:
import 'dart:ffi';
final class C extends Struct {
@Array.variable()
external Array<Uint8> a0;
@Uint8()
external int a1;
}
Common fixes
#Move the variable length inline Array
to be the last field in the struct.
import 'dart:ffi';
final class C extends Struct {
@Uint8()
external int a1;
@Array.variable()
external Array<Uint8> a0;
}
If the inline array has a fixed size, annotate it with the size:
import 'dart:ffi';
final class C extends Struct {
@Array(10)
external Array<Uint8> a0;
@Uint8()
external int a1;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.