Add FilamentModel with all properties and refactor notes as optional

This commit is contained in:
2026-03-03 09:11:38 +01:00
commit 18c156c9d1
62 changed files with 192467 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
class FilamentModel {
final String documentId;
final String name;
final String type;
final String color;
final double weight;
final double weightUsed;
final double price;
final String manufacture;
final String purchaseDate;
final String? notes;
final int printingTemp;
final int bedTemp;
FilamentModel({
required this.documentId,
required this.name,
required this.type,
required this.color,
required this.weight,
required this.weightUsed,
required this.price,
required this.manufacture,
required this.purchaseDate,
this.notes,
required this.printingTemp,
required this.bedTemp,
});
static FilamentModel fromJson(Map<String, dynamic> json) {
return FilamentModel(
documentId: json['\$id'],
name: json['name'],
type: json['type'],
color: json['color'],
weight: (json['weight'] as num).toDouble(),
weightUsed: (json['weightUsed'] as num).toDouble(),
price: (json['price'] as num).toDouble(),
manufacture: json['manufacture'],
purchaseDate: json['purchaseDate'],
notes: json['notes'] as String?,
printingTemp: json['printingTemp'],
bedTemp: json['bedTemp'],
);
}
static Map<String, dynamic> toMapForAppwrite(FilamentModel filamentModel) {
return {
'name': filamentModel.name,
'type': filamentModel.type,
'color': filamentModel.color,
'weight': filamentModel.weight,
'weightUsed': filamentModel.weightUsed,
'price': filamentModel.price,
'manufacture': filamentModel.manufacture,
'purchaseDate': filamentModel.purchaseDate,
if (filamentModel.notes != null) 'notes': filamentModel.notes,
'printingTemp': filamentModel.printingTemp,
'bedTemp': filamentModel.bedTemp,
};
}
// An empty instance for initialization or default values
static final empty = FilamentModel(
documentId: '00',
name: '',
type: '',
color: '',
weight: 0.0,
weightUsed: 0.0,
price: 0.0,
manufacture: '',
purchaseDate: '',
notes: null,
printingTemp: 0,
bedTemp: 0,
);
}

View File

@@ -0,0 +1,90 @@
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',
// ),
// ];
}