boxchecker/lib/data_util.dart

76 lines
1.6 KiB
Dart

import 'dart:core';
import 'dart:core' as core;
import 'package:hive/hive.dart';
part 'data_util.g.dart';
enum Page { lists, templates }
@HiveType(typeId: 1)
class List {
List(
this.name, {
this.id,
this.description,
this.isTemplate,
this.checks = const [],
});
@HiveField(0)
int? id;
@HiveField(1)
String name;
@HiveField(2)
String? description;
@HiveField(3)
bool? isTemplate;
@HiveField(4)
core.List<Check> checks;
Map<String, dynamic> toMap() {
var map = <String, dynamic>{};
if (id != null) map["id"] = id;
map["list_name"] = name;
if (description != null) map["list_desc"] = description;
if (isTemplate != null) map["is_template"] = isTemplate! ? 1 : 0;
return map;
}
static List fromMap(Map<String, dynamic> map) {
return List(
map["list_name"],
id: map["id"],
description: map["list_desc"],
isTemplate: map["is_template"] == 1,
);
}
}
@HiveType(typeId: 2)
class Check {
Check(this.text, this.value, {this.id, this.listID});
@HiveField(5)
int? id;
@HiveField(6)
String text;
@HiveField(7)
bool value;
@HiveField(8)
int? listID;
Map<String, dynamic> toMap() {
var map = <String, dynamic>{};
if (id != null) map["id"] = id;
map["check_text"] = text;
map["status"] = value ? 1 : 0;
if (listID != null) map["list_id"] = listID!;
return map;
}
static Check fromMap(Map<String, dynamic> map) {
return Check(map["check_text"], map["status"] == 1,
id: map["id"], listID: map["list_id"]);
}
}