Add view and logik

This commit is contained in:
2026-04-01 14:28:38 +02:00
parent bf8fd37e51
commit 122ae48754
30 changed files with 1926 additions and 176 deletions

View 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,
),
];
}

View File

@@ -0,0 +1,48 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:convert';
class UserModel {
final String uuid;
final String username;
final String passwort;
UserModel({
required this.uuid,
required this.username,
required this.passwort,
});
UserModel copyWith({
String? uuid,
String? username,
String? passwort,
}) {
return UserModel(
uuid: uuid ?? this.uuid,
username: username ?? this.username,
passwort: passwort ?? this.passwort,
);
}
Map<String, dynamic> toMap() {
return <String, dynamic>{
'pk_userUuid': uuid,
'benutzer': username,
'kennwort': passwort,
};
}
factory UserModel.fromMap(Map<String, dynamic> map) {
return UserModel(
uuid: map['pk_userUuid'] as String,
username: map['benutzer'] as String,
passwort: map['kennwort'] as String,
);
}
String toJson() => json.encode(toMap());
factory UserModel.fromJson(String source) => UserModel.fromMap(json.decode(source) as Map<String, dynamic>);
@override
String toString() => 'UserModel(uuid: $uuid, username: $username, passwort: $passwort)';
}