cpd/lib/database/habit.dart

36 lines
810 B
Dart
Raw Normal View History

import 'package:flutter/cupertino.dart';
class Habit {
final int id;
bool isComplete;
String title;
String? subtitle;
IconData icon;
Habit({
required this.id,
required this.isComplete,
required this.title,
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,
};
}
}