diameter/lib/models/basal_profile.dart

40 lines
986 B
Dart
Raw Normal View History

import 'package:diameter/main.dart';
import 'package:diameter/objectbox.g.dart';
2021-11-25 18:25:13 +00:00
// ignore: unnecessary_import
import 'package:objectbox/objectbox.dart';
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>();
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());
2021-10-22 23:08:09 +00:00
}
}