Add view and logik
This commit is contained in:
157
lib/models/filament_model.dart
Normal file
157
lib/models/filament_model.dart
Normal file
@@ -0,0 +1,157 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class FilamentModel {
|
||||
final String id;
|
||||
final String name;
|
||||
final String type; // PLA, ABS, PETG, etc.
|
||||
final String color;
|
||||
final int weight; // in Gramm
|
||||
final int weightUsed;
|
||||
final double price; // Preis
|
||||
final String? manufacturer;
|
||||
final String? purchaseDate;
|
||||
final String? notes;
|
||||
final int pices;
|
||||
final int printingTemp;
|
||||
final int bedTemp;
|
||||
|
||||
FilamentModel({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.type,
|
||||
required this.color,
|
||||
required this.weight,
|
||||
required this.weightUsed,
|
||||
required this.price,
|
||||
this.manufacturer,
|
||||
this.purchaseDate,
|
||||
this.notes,
|
||||
required this.pices,
|
||||
required this.printingTemp,
|
||||
required this.bedTemp,
|
||||
});
|
||||
|
||||
// JSON Serialisierung
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'type': type,
|
||||
'color': color,
|
||||
'weight': weight,
|
||||
'price': price,
|
||||
'manufacturer': manufacturer,
|
||||
'purchaseDate': purchaseDate,
|
||||
'notes': notes,
|
||||
'pices': pices,
|
||||
'printingTemp': printingTemp,
|
||||
'bedTemp': bedTemp,
|
||||
'weightUsed': weightUsed,
|
||||
};
|
||||
}
|
||||
|
||||
// JSON Deserialisierung
|
||||
factory FilamentModel.fromJson(Map<String, dynamic> json) {
|
||||
return FilamentModel(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
type: json['type'] as String,
|
||||
color: json['color'] as String,
|
||||
weight: json['weight'] as int? ?? 0,
|
||||
weightUsed: json['weightUsed'] as int? ?? 0,
|
||||
price: (json['price'] as num).toDouble(),
|
||||
manufacturer: json['manufacturer'] as String?,
|
||||
purchaseDate: json['purchaseDate'] as String?,
|
||||
notes: json['notes'] as String?,
|
||||
pices: json['pices'] as int,
|
||||
printingTemp: json['printingTemp'] as int,
|
||||
bedTemp: json['bedTemp'] as int,
|
||||
);
|
||||
}
|
||||
|
||||
// CopyWith für Updates
|
||||
FilamentModel copyWith({
|
||||
String? id,
|
||||
String? name,
|
||||
String? type,
|
||||
String? color,
|
||||
int? weight,
|
||||
int? weightUsed,
|
||||
double? price,
|
||||
String? manufacturer,
|
||||
String? purchaseDate,
|
||||
String? notes,
|
||||
int? pices,
|
||||
int? printingTemp,
|
||||
int? bedTemp,
|
||||
}) {
|
||||
return FilamentModel(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
type: type ?? this.type,
|
||||
color: color ?? this.color,
|
||||
weight: weight ?? this.weight,
|
||||
weightUsed: weightUsed ?? this.weightUsed,
|
||||
price: price ?? this.price,
|
||||
manufacturer: manufacturer ?? this.manufacturer,
|
||||
purchaseDate: purchaseDate ?? this.purchaseDate,
|
||||
notes: notes ?? this.notes,
|
||||
pices: pices ?? this.pices,
|
||||
printingTemp: printingTemp ?? this.printingTemp,
|
||||
bedTemp: bedTemp ?? this.bedTemp,
|
||||
);
|
||||
}
|
||||
|
||||
static String formatDate(DateTime date) {
|
||||
final DateFormat formatter = DateFormat('dd.MM.yyyy');
|
||||
return formatter.format(date);
|
||||
}
|
||||
|
||||
static List<FilamentModel> mockupFilamentList = [
|
||||
FilamentModel(
|
||||
id: '1',
|
||||
name: '3Djake ECO Filament',
|
||||
type: 'PLA',
|
||||
color: 'White',
|
||||
weight: 1000,
|
||||
weightUsed: 250,
|
||||
price: 19.99,
|
||||
manufacturer: '3Djake.at',
|
||||
purchaseDate: formatDate(DateTime(2026, 1, 10)),
|
||||
notes: 'Great quality filament for everyday printing.',
|
||||
pices: 1,
|
||||
printingTemp: 207,
|
||||
bedTemp: 55,
|
||||
),
|
||||
FilamentModel(
|
||||
id: '2',
|
||||
name: 'Geeetech',
|
||||
type: 'PETG',
|
||||
color: 'Black',
|
||||
weight: 1000,
|
||||
weightUsed: 0,
|
||||
price: 9.99,
|
||||
manufacturer: 'geeetech.com',
|
||||
purchaseDate: formatDate(DateTime(2025, 10, 10)),
|
||||
notes: 'Durable and strong, perfect for functional parts.',
|
||||
pices: 8,
|
||||
printingTemp: 207,
|
||||
bedTemp: 55,
|
||||
),
|
||||
FilamentModel(
|
||||
id: '3',
|
||||
name: 'Tinmorry',
|
||||
type: 'ASA',
|
||||
color: 'Black',
|
||||
weight: 1000,
|
||||
weightUsed: 150,
|
||||
price: 16.01,
|
||||
pices: 1,
|
||||
manufacturer: 'tinmorry.com',
|
||||
purchaseDate: formatDate(DateTime(2026, 1, 10)),
|
||||
notes: 'Weather-resistant filament for outdoor use.',
|
||||
printingTemp: 265,
|
||||
bedTemp: 100,
|
||||
),
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user