2024-05-19 22:08:04 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2024-05-12 00:08:54 +02:00
|
|
|
|
|
|
|
class Habit {
|
|
|
|
final int id;
|
|
|
|
bool isComplete;
|
|
|
|
String title;
|
|
|
|
String? subtitle;
|
2024-05-19 22:08:04 +02:00
|
|
|
IconData icon;
|
2024-05-12 00:08:54 +02:00
|
|
|
|
|
|
|
Habit({
|
|
|
|
required this.id,
|
|
|
|
required this.isComplete,
|
|
|
|
required this.title,
|
|
|
|
this.subtitle,
|
2024-05-19 22:08:04 +02:00
|
|
|
required this.icon,
|
2024-05-12 00:08:54 +02:00
|
|
|
});
|
|
|
|
|
2024-05-19 22:08:04 +02:00
|
|
|
factory Habit.fromSqfliteDatabase(Map<String, dynamic> map) =>
|
|
|
|
Habit(
|
|
|
|
id: map['id']?.toInt() ?? 0,
|
|
|
|
isComplete: map['isComplete'] == 1,
|
|
|
|
title: map['title'] ?? '',
|
|
|
|
subtitle: map['subtitle'] ?? '',
|
|
|
|
icon: IconData(map['icon'] is int ? map['icon'] : 0, fontFamily: 'MaterialIcons'),
|
|
|
|
);
|
2024-05-12 00:08:54 +02:00
|
|
|
|
2024-05-19 22:08:04 +02:00
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {
|
|
|
|
'id': id,
|
|
|
|
'title': title,
|
|
|
|
'subtitle': subtitle,
|
|
|
|
'isComplete': isComplete ? 1 : 0,
|
|
|
|
'icon': icon.codePoint,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|