diameter/lib/models/basal_profile.dart

60 lines
1.3 KiB
Dart
Raw Normal View History

import 'package:diameter/main.dart';
2021-11-25 18:25:13 +00:00
import 'package:objectbox/objectbox.dart';
import 'package:diameter/objectbox.g.dart' show BasalProfile_;
2021-10-22 23:08:09 +00:00
@Entity(uid: 3613736032926903785)
2021-10-22 23:08:09 +00:00
class BasalProfile {
static final Box<BasalProfile> box = objectBox.store.box<BasalProfile>();
// properties
int id;
bool deleted;
String name;
bool active;
String? notes;
// constructor
BasalProfile({
this.id = 0,
this.deleted = false,
this.name = '',
this.active = false,
this.notes,
});
// methods
static BasalProfile? get(int id) => box.get(id);
static void put(BasalProfile basalProfile) => box.put(basalProfile);
static List<BasalProfile> getAll() {
QueryBuilder<BasalProfile> all = box.query(BasalProfile_.deleted.equals(false));
return all.build().find();
}
static void remove(int id) {
final item = box.get(id);
if (item != null) {
item.deleted = true;
box.put(item);
}
}
static int activeCount() {
Query<BasalProfile> query = box
.query(BasalProfile_.active.equals(true) & BasalProfile_.deleted.equals(false)).build();
return query.find().length;
}
static void setAllInactive() {
box.putMany(box.getAll().map((item) {
item.active = false;
return item;
}).toList());
2021-10-22 23:08:09 +00:00
}
@override
String toString() {
return name;
}
2021-10-22 23:08:09 +00:00
}