dart Flutter落镖:ffi '未找到

niwlg2el  于 2023-01-22  发布在  Flutter
关注(0)|答案(1)|浏览(252)

我想创建一个数据类,并在我的数据类中放入一些属性。下面是我的代码:

import 'dart:ffi';
class UserDetail {
  final Long id;
  final String name;
  final String phone;
  final String creditCardNumber;
  final String nationalId;
  final Int score;
  UserDetail(this.id, this.name, this.phone, this.creditCardNumber,
      this.nationalId, this.score);
  factory UserDetail.fromJson(Map<String, dynamic> json) {
    return UserDetail(
        json['id'],
        json['name'],
        json['phone'],
        json['creditCardNumber'],
        json['nationalId'],
        json['score']
    );
  }
}

问题是当我想运行这个项目时,我得到这个错误:

lib/domain/UserDetail.dart:1:8: Error: Not found: 'dart:ffi'
    import 'dart:ffi';
           ^
    lib/domain/UserDetail.dart:5:9: Error: Type 'Long' not found.
      final Long id;
            ^^^^
    lib/domain/UserDetail.dart:10:9: Error: Type 'Int' not found.
      final Int score;
            ^^^
    lib/domain/UserDetail.dart:5:9: Error: 'Long' isn't a type.
      final Long id;
            ^^^^
    lib/domain/UserDetail.dart:10:9: Error: 'Int' isn't a type.
      final Int score;
            ^^^
    Failed to compile application.

我不明白为什么Int不是一个类型!我该如何解决这个问题?

s6fujrry

s6fujrry1#

只需删除导入dart:ffi;导入,另外LongIntDart中不是有效的数据类型,请使用int代替它们

class UserDetail {
  final int id;
  final String name;
  final String phone;
  final String creditCardNumber;
  final String nationalId;
  final int score;

  UserDetail(this.id, this.name, this.phone, this.creditCardNumber, this.nationalId, this.score);

  factory UserDetail.fromJson(Map<String, dynamic> json) {
    return UserDetail(
        json['id'],
        json['name'],
        json['phone'],
        json['creditCardNumber'],
        json['nationalId'],
        json['score']
    );
  }
}

相关问题