Home > OS >  flutter `dart:ffi` Notfound
flutter `dart:ffi` Notfound

Time:01-20

I want to create a data class and put some attributes in my data class. here is my code:

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']
    );
  }
}

the problem is when I want to run the project I get this error:

    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.

I don't understand why Int is not a type! and how can I solve this problem?

CodePudding user response:

Just remove import dart:ffi; import, also Long and Int are not valid data types in Dart, use int instead of them

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']
    );
  }
}
  •  Tags:  
  • dart
  • Related