boxchecker/lib/data_util.dart

52 lines
1.3 KiB
Dart
Raw Normal View History

enum Page { lists, templates }
class List {
2021-11-04 13:02:40 -04:00
List(this.name, {this.id, this.description, this.isTemplate});
2021-11-03 14:52:39 -04:00
int? id;
String name;
2021-11-04 13:02:40 -04:00
String? description;
bool? isTemplate;
Map<String, dynamic> toMap() {
var map = Map<String, dynamic>();
2021-11-03 14:52:39 -04:00
if (id != null) map["id"] = this.id;
map["list_name"] = this.name;
2021-11-04 13:02:40 -04:00
if (description != null) map["list_desc"] = description;
2021-11-03 14:52:39 -04:00
if (isTemplate != null) map["is_template"] = isTemplate! ? 1 : 0;
return map;
}
static List fromMap(Map<String, dynamic> map) {
2021-11-04 13:02:40 -04:00
return List(
map["list_name"],
id: map["id"],
description: map["list_desc"],
isTemplate: map["is_template"] == 1,
);
}
}
class Check {
2021-11-03 14:52:39 -04:00
Check(this.text, this.value, {this.id, this.listID});
2021-11-03 14:52:39 -04:00
int? id;
String text;
bool value;
int? listID;
Map<String, dynamic> toMap() {
var map = Map<String, dynamic>();
2021-11-03 14:52:39 -04:00
if (id != null) map["id"] = this.id;
map["check_text"] = this.text;
2021-11-03 17:28:03 -04:00
map["status"] = this.value ? 1 : 0;
2021-11-03 14:52:39 -04:00
if (listID != null) map["list_id"] = this.listID! as int;
return map;
}
static Check fromMap(Map<String, dynamic> map) {
2021-11-03 17:28:03 -04:00
return Check(map["check_text"], map["status"] == 1,
2021-11-03 14:52:39 -04:00
id: map["id"], listID: map["list_id"]);
}
}