prasule/lib/api/category.dart
Matyáš Caras cfd4d6200e
chore: cosmetic changes
Change some comment text, also change current balance to a getter
2024-01-31 07:54:29 +01:00

60 lines
1.5 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 {
/// Represents a category in a user's wallet
WalletCategory({
required this.name,
required this.id,
required this.icon,
required this.color,
});
/// Connects the generated fromJson method
factory WalletCategory.fromJson(Map<String, dynamic> json) =>
_$WalletCategoryFromJson(json);
/// User-defined name
String name;
/// Unique identificator of the category
final int id;
/// Selected Icon for the category
@JsonKey(fromJson: _iconDataFromJson, toJson: _iconDataToJson)
IconData icon;
/// The color that will be displayed with entry
@JsonKey(fromJson: _colorFromJson, toJson: _colorToJson)
Color color;
/// Connects the generated 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'] as int, fontFamily: data['family'] as String?);
int _colorToJson(Color color) => color.value;
Color _colorFromJson(int input) => Color(input);
/// Type of entry, either expense or income
enum EntryType {
/// Expense
expense,
/// Income
income
}