2024-06-09 17:45:17 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2024-05-12 00:08:54 +02:00
|
|
|
|
|
|
|
class Habit {
|
|
|
|
final int id;
|
|
|
|
bool isComplete;
|
|
|
|
String title;
|
2024-05-24 00:01:08 +02:00
|
|
|
String subtitle;
|
2024-06-09 17:45:17 +02:00
|
|
|
int iconCodePoint;
|
|
|
|
String iconFontFamily;
|
2024-05-12 00:08:54 +02:00
|
|
|
|
|
|
|
Habit({
|
|
|
|
required this.id,
|
|
|
|
required this.isComplete,
|
|
|
|
required this.title,
|
2024-05-24 00:01:08 +02:00
|
|
|
required this.subtitle,
|
2024-06-09 17:45:17 +02:00
|
|
|
required this.iconCodePoint,
|
|
|
|
required this.iconFontFamily,
|
2024-05-12 00:08:54 +02:00
|
|
|
});
|
|
|
|
|
2024-06-09 17:45:17 +02:00
|
|
|
IconData get icon => IconData(iconCodePoint, fontFamily: iconFontFamily);
|
|
|
|
|
|
|
|
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',
|
|
|
|
);
|
|
|
|
}
|
2024-05-12 00:08:54 +02:00
|
|
|
|
2024-06-16 17:12:28 +02:00
|
|
|
//konvertiert das Habit-Objekt in eine Map zum Speichern in der DB
|
2024-05-19 22:08:04 +02:00
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {
|
|
|
|
'id': id,
|
|
|
|
'title': title,
|
|
|
|
'subtitle': subtitle,
|
|
|
|
'isComplete': isComplete ? 1 : 0,
|
2024-06-09 17:45:17 +02:00
|
|
|
'iconCodePoint': iconCodePoint,
|
|
|
|
'iconFontFamily': iconFontFamily,
|
2024-05-19 22:08:04 +02:00
|
|
|
};
|
2024-05-28 21:59:44 +02:00
|
|
|
}
|
2024-06-16 17:12:28 +02:00
|
|
|
}
|