Files
filament-tracker/lib/models/home_model.dart

91 lines
2.3 KiB
Dart

class WeightModel {
final String documentId;
final String name;
final double weight;
final DateTime date;
final double weightChange;
WeightModel({
required this.weight,
required this.date,
required this.weightChange,
required this.name,
required this.documentId,
});
static WeightModel fromJson(Map<String, dynamic> json) {
return WeightModel(
weight: json['weight'],
date: DateTime.parse(json['date']),
weightChange: json['weightChange'],
name: json['name'],
documentId: json['\$id'],
);
}
static Map<String, dynamic> toMapForAppwrite(WeightModel weightModel) {
return {
'weight': weightModel.weight,
'date': weightModel.date.toIso8601String(),
'weightChange': weightModel.weightChange,
'name': weightModel.name,
//'\$id': weightModel.documentId,
};
}
// An empty instance for initialization or default values
static final empty = WeightModel(
weight: 0.0,
date: DateTime.now(),
weightChange: 0.0,
name: 'Joe',
documentId: '00',
);
// Sample data for testing and demonstration purposes
// static List<WeightModel> sampleData = [
// WeightModel(
// weight: 70.0,
// date: DateTime(2024, 1, 1),
// weightChange: 0.0,
// name: 'Joe',
// documentId: '699e0c79003da44797d9',
// ),
// WeightModel(
// weight: 69.2,
// date: DateTime(2024, 1, 15),
// weightChange: -0.5,
// name: 'Joe',
// documentId: '699e0ca5002697256161',
// ),
// WeightModel(
// weight: 68.0,
// date: DateTime(2024, 2, 1),
// weightChange: -1.5,
// name: 'Joe',
// documentId: '699e0cdc00352f911abe',
// ),
// WeightModel(
// weight: 100.0,
// date: DateTime(2024, 1, 1),
// weightChange: 0.0,
// name: 'Karl',
// documentId: '699e0cfd0014079d20b7',
// ),
// WeightModel(
// weight: 95.5,
// date: DateTime(2024, 1, 15),
// weightChange: -4.5,
// name: 'Karl',
// documentId: '699e0d2100090bef253b',
// ),
// WeightModel(
// weight: 90.0,
// date: DateTime(2024, 2, 1),
// weightChange: -5.5,
// name: 'Karl',
// documentId: '699e0d40001f669c6a15',
// ),
// ];
}