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, required this.subtitle, required this.icon, }); factory Habit.fromSqfliteDatabase(Map 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 toMap() { return { 'id': id, 'title': title, 'subtitle': subtitle, 'isComplete': isComplete ? 1 : 0, 'icon': icon.codePoint, }; } factory Habit.fromMap(Map map) { return Habit( id: map['id'], title: map['title'], subtitle: map['subtitle'], icon: map['icon'], isComplete: map['isComplete'] == 1, ); } }