import 'package:flutter/material.dart'; class Habit { final int id; bool isComplete; String title; String subtitle; int iconCodePoint; String iconFontFamily; Habit({ required this.id, required this.isComplete, required this.title, required this.subtitle, required this.iconCodePoint, required this.iconFontFamily, }); IconData get icon => IconData(iconCodePoint, fontFamily: iconFontFamily); // Methode zum Aktualisieren der Icon-Daten void updateIcon(int newCodePoint, String newFontFamily) { iconCodePoint = newCodePoint; iconFontFamily = newFontFamily; } //erstellt ein Habit-Objekt aus der DB-Abfrage factory Habit.fromSqfliteDatabase(Map map) { return Habit( id: map['id']?.toInt() ?? 0, isComplete: map['isComplete'] == 1, title: map['title'] ?? '', subtitle: map['subtitle'] ?? '', iconCodePoint: map['iconCodePoint']?.toInt() ?? Icons.favorite.codePoint, iconFontFamily: map['iconFontFamily'] ?? 'MaterialIcons', ); } //konvertiert das Habit-Objekt in eine Map zum Speichern in der DB Map toMap() { return { 'id': id, 'title': title, 'subtitle': subtitle, 'isComplete': isComplete ? 1 : 0, 'iconCodePoint': iconCodePoint, 'iconFontFamily': iconFontFamily, }; } }