diameter/lib/models/basal_profile.dart
2021-11-25 19:25:13 +01:00

40 lines
986 B
Dart

import 'package:diameter/main.dart';
import 'package:diameter/objectbox.g.dart';
// ignore: unnecessary_import
import 'package:objectbox/objectbox.dart';
@Entity(uid: 3613736032926903785)
class BasalProfile {
static final Box<BasalProfile> box = objectBox.store.box<BasalProfile>();
int id;
String name;
bool active;
String? notes;
BasalProfile({
this.id = 0,
this.name = '',
this.active = false,
this.notes,
});
static BasalProfile? get(int id) => box.get(id);
static List<BasalProfile> getAll() => box.getAll();
static void put(BasalProfile basalProfile) => box.put(basalProfile);
static void remove(int id) => box.remove(id);
static int activeCount() {
Query<BasalProfile> query =
box.query(BasalProfile_.active.equals(true)).build();
return query.find().length;
}
static void setAllInactive() {
box.putMany(box.getAll().map((element) {
element.active = false;
return element;
}).toList());
}
}