cpd/lib/database/habit.dart

49 lines
1.2 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
class Habit {
final int id;
bool isComplete;
String title;
2024-05-24 00:01:08 +02:00
String subtitle;
int iconCodePoint;
String iconFontFamily;
Habit({
required this.id,
required this.isComplete,
required this.title,
2024-05-24 00:01:08 +02:00
required this.subtitle,
required this.iconCodePoint,
required this.iconFontFamily,
});
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',
);
}
//konvertiert das Habit-Objekt in eine Map zum Speichern in der DB
Map<String, dynamic> toMap() {
return {
'id': id,
'title': title,
'subtitle': subtitle,
'isComplete': isComplete ? 1 : 0,
'iconCodePoint': iconCodePoint,
'iconFontFamily': iconFontFamily,
};
}
}