prasule/lib/api/entry_data.dart

35 lines
979 B
Dart

// SPDX-FileCopyrightText: (C) 2024 Matyáš Caras
//
// SPDX-License-Identifier: AGPL-3.0-only
import 'package:json_annotation/json_annotation.dart';
part 'entry_data.g.dart';
/// Contains raw data
@JsonSerializable()
class EntryData {
/// Contains raw data
EntryData({required this.name, required this.amount, this.description = ""});
/// Generates a class instance from a Map
factory EntryData.fromJson(Map<String, dynamic> json) =>
_$EntryDataFromJson(json);
/// [EntryData] instance used as a default value for json_serializable
factory EntryData.unknown() => EntryData(name: "Unknown", amount: 0);
/// Name of entry
@JsonKey(defaultValue: "Unknown")
String name;
/// Optional description, default is empty
@JsonKey(defaultValue: "")
String description;
/// Amount for entry
@JsonKey(defaultValue: 0)
double amount;
/// Converts the data in this instance into a Map
Map<String, dynamic> toJson() => _$EntryDataToJson(this);
}