cpd/lib/database/habit.dart

50 lines
1.2 KiB
Dart

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;
}
factory Habit.fromSqfliteDatabase(Map<String, dynamic> 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',
);
}
Map<String, dynamic> toMap() {
return {
'id': id,
'title': title,
'subtitle': subtitle,
'isComplete': isComplete ? 1 : 0,
'iconCodePoint': iconCodePoint,
'iconFontFamily': iconFontFamily,
};
}
}