cpd/lib/database/habit.dart

36 lines
818 B
Dart
Raw Normal View History

import 'package:flutter/cupertino.dart';
class Habit {
final int id;
bool isComplete;
String title;
2024-05-24 00:01:08 +02:00
String subtitle;
IconData icon;
Habit({
required this.id,
required this.isComplete,
required this.title,
2024-05-24 00:01:08 +02:00
required this.subtitle,
required this.icon,
});
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'),
);
Map<String, dynamic> toMap() {
return {
'id': id,
'title': title,
'subtitle': subtitle,
'isComplete': isComplete ? 1 : 0,
'icon': icon.codePoint,
};
}
}