47 lines
1.0 KiB
Dart
47 lines
1.0 KiB
Dart
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<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,
|
|
};
|
|
}
|
|
|
|
factory Habit.fromMap(Map<String, dynamic> map) {
|
|
return Habit(
|
|
id: map['id'],
|
|
title: map['title'],
|
|
subtitle: map['subtitle'],
|
|
icon: map['icon'],
|
|
isComplete: map['isComplete'] == 1,
|
|
);
|
|
}
|
|
}
|