필드의 선언된 타입과 맞지 않는 어노테이션

필드의 선언된 타입과 맞지 않는 어노테이션 (mismatched_annotation_on_struct_field)

StructUnion을 상속받는 클래스의 필드에 붙인 어노테이션이 그 필드의 Dart 타입과 어긋날 때 분석기가 알려주는 진단이에요. C 타입을 나타내는 어노테이션과 필드의 Dart 타입을 서로 맞춰주면 바로 풀리는 문제죠.

출처: The annotation doesn't match the declared type of the field.

본문

이 진단은 StructUnion을 상속받는 클래스의 필드에 붙은 어노테이션이 그 필드의 Dart 타입과 맞지 않을 때 분석기가 만들어내요.

FFI에 대해 더 알고 싶다면 C interop using dart:ffi 문서를 참고하세요.

예시

아래 코드는 Double 어노테이션이 Dart 타입 int와 맞지 않아서 이 진단이 나와요.

import 'dart:ffi';

final class C extends Struct {
  @Double()
  external int x;
}

해결 방법

필드의 타입이 올바르다면, 어노테이션을 그에 맞게 바꿔주세요.

import 'dart:ffi';

final class C extends Struct {
  @Int32()
  external int x;
}

어노테이션이 올바르다면, 필드의 타입을 그에 맞게 바꿔주세요.

import 'dart:ffi';

final class C extends Struct {
  @Double()
  external double x;
}

더 알아보기