40 lines
1.1 KiB
Dart
40 lines
1.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:json_annotation/json_annotation.dart';
|
|
part 'category.g.dart';
|
|
|
|
@JsonSerializable()
|
|
|
|
/// Represents a category in a user's wallet
|
|
class WalletCategory {
|
|
final EntryType type;
|
|
String name;
|
|
final int id;
|
|
@JsonKey(fromJson: _iconDataFromJson, toJson: _iconDataToJson)
|
|
IconData icon;
|
|
|
|
WalletCategory(
|
|
{required this.name,
|
|
required this.type,
|
|
required this.id,
|
|
required this.icon});
|
|
|
|
/// Connect the generated [_$WalletEntry] function to the `fromJson`
|
|
/// factory.
|
|
factory WalletCategory.fromJson(Map<String, dynamic> json) =>
|
|
_$WalletCategoryFromJson(json);
|
|
|
|
/// Connect the generated [_$PersonToJson] function to the `toJson` method.
|
|
Map<String, dynamic> toJson() => _$WalletCategoryToJson(this);
|
|
|
|
@override
|
|
String toString() {
|
|
return name;
|
|
}
|
|
}
|
|
|
|
Map<String, dynamic> _iconDataToJson(IconData icon) =>
|
|
{'codepoint': icon.codePoint, 'family': icon.fontFamily};
|
|
IconData _iconDataFromJson(Map<String, dynamic> data) =>
|
|
IconData(data['codepoint'], fontFamily: data['family']);
|
|
|
|
enum EntryType { expense, income }
|