43 lines
1.0 KiB
Dart
43 lines
1.0 KiB
Dart
// lib/models/firefly_account.dart
|
|
|
|
/// Represents an account retrieved from the Firefly III API.
|
|
class FireflyAccount {
|
|
final String id;
|
|
final String name;
|
|
final String type;
|
|
// Tambahkan field lain jika diperlukan, seperti currency, balance, dll.
|
|
|
|
FireflyAccount({
|
|
required this.id,
|
|
required this.name,
|
|
required this.type,
|
|
});
|
|
|
|
/// Creates a FireflyAccount instance from a JSON object.
|
|
factory FireflyAccount.fromJson(Map<String, dynamic> json) {
|
|
final attributes = json['attributes'] as Map<String, dynamic>;
|
|
return FireflyAccount(
|
|
id: json['id'].toString(), // ID bisa string atau int, pastikan konsisten
|
|
name: attributes['name'] as String,
|
|
type: attributes['type'] as String,
|
|
);
|
|
}
|
|
|
|
/// Converts a FireflyAccount instance to a JSON object.
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'attributes': {
|
|
'name': name,
|
|
'type': type,
|
|
}
|
|
};
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
// Digunakan untuk menampilkan nama akun di dropdown
|
|
return name;
|
|
}
|
|
}
|