diameter/lib/models/meal_category.dart

46 lines
1019 B
Dart
Raw Normal View History

import 'package:diameter/main.dart';
import 'package:objectbox/objectbox.dart';
2021-12-06 22:09:40 +00:00
import 'package:diameter/objectbox.g.dart' show MealCategory_;
2021-10-22 23:08:09 +00:00
@Entity(uid: 3158200688796904913)
2021-12-09 05:14:55 +00:00
@Sync()
2021-10-22 23:08:09 +00:00
class MealCategory {
static final Box<MealCategory> box = objectBox.store.box<MealCategory>();
// properties
int id;
bool deleted;
String value;
String? notes;
// constructor
MealCategory({
this.id = 0,
this.deleted = false,
this.value = '',
this.notes,
});
// methods
static MealCategory? get(int id) => box.get(id);
static void put(MealCategory mealCategory) => box.put(mealCategory);
2021-12-06 22:09:40 +00:00
static List<MealCategory> getAll() {
QueryBuilder<MealCategory> builder = box.query(MealCategory_.deleted.equals(false))..order(MealCategory_.value);
return builder.build().find();
}
static void remove(int id) {
final item = box.get(id);
if (item != null) {
item.deleted = true;
box.put(item);
}
}
@override
String toString() {
return value;
}
2021-10-22 23:08:09 +00:00
}