also switched hive box access to static const strings in the (entity) classes
This commit is contained in:
parent
2909f1c1d0
commit
d697fdb7ef
11 changed files with 14 additions and 11 deletions
|
@ -11,6 +11,8 @@ part 'pizza_recipe.g.dart';
|
|||
|
||||
@HiveType(typeId: 0)
|
||||
class PizzaRecipe extends HiveObject {
|
||||
static const String hiveName = "PizzaRecipes";
|
||||
|
||||
@HiveField(0)
|
||||
String name;
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ part 'pizza_event.g.dart';
|
|||
|
||||
@HiveType(typeId: 4)
|
||||
class PizzaEvent extends HiveObject{
|
||||
static const String hiveName = "PizzaEvent";
|
||||
|
||||
@HiveField(0)
|
||||
String name;
|
||||
|
||||
|
|
|
@ -42,8 +42,8 @@ Future<void> main() async {
|
|||
Hive.registerAdapter(RecipeSubStepAdapter());
|
||||
Hive.registerAdapter(IngredientAdapter());
|
||||
|
||||
await Hive.openBox<PizzaEvent>("PizzaEvents");
|
||||
final pizzaRecipesBox = await Hive.openBox<PizzaRecipe>("PizzaRecipes");
|
||||
await Hive.openBox<PizzaEvent>(PizzaEvent.hiveName);
|
||||
final pizzaRecipesBox = await Hive.openBox<PizzaRecipe>(PizzaRecipe.hiveName);
|
||||
|
||||
if (pizzaRecipesBox.isEmpty){
|
||||
pizzaRecipesBox.addAll(await getRecipes());
|
||||
|
|
|
@ -174,7 +174,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
|
|||
.add(const Duration(minutes: 1));
|
||||
}
|
||||
|
||||
final pizzaEventsBox = Hive.box<PizzaEvent>("PizzaEvents");
|
||||
final pizzaEventsBox = Hive.box<PizzaEvent>(PizzaEvent.hiveName);
|
||||
final PizzaEvent pizzaEvent = PizzaEvent(
|
||||
name,
|
||||
widget.pizzaRecipe,
|
||||
|
|
|
@ -207,7 +207,7 @@ class AddRecipeURLPageState extends State<AddRecipeURLPage> {
|
|||
}
|
||||
|
||||
Future<void> addPizzaRecipeToBox(PizzaRecipe pizzaRecipe) async {
|
||||
final pizzaRecipeBox = Hive.box<PizzaRecipe>("PizzaRecipes");
|
||||
final pizzaRecipeBox = Hive.box<PizzaRecipe>(PizzaRecipe.hiveName);
|
||||
if (pizzaRecipeBox.containsKey(pizzaRecipe.key)) {
|
||||
return; // this recipe is already in the box
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ class EditRecipePageState extends State<EditRecipePage> {
|
|||
if (pizzaRecipe.isInBox){
|
||||
pizzaRecipe.save();
|
||||
} else {
|
||||
final pizzaRecipesBox = await Hive.openBox<PizzaRecipe>("PizzaRecipes");
|
||||
final pizzaRecipesBox = await Hive.openBox<PizzaRecipe>(PizzaRecipe.hiveName);
|
||||
pizzaRecipesBox.add(pizzaRecipe);
|
||||
}
|
||||
if (!mounted){
|
||||
|
|
|
@ -13,7 +13,7 @@ class PickPizzaRecipePage extends StatelessWidget {
|
|||
return PizzaPlannerScaffold(
|
||||
title: const Text("Pick Recipe"),
|
||||
body: ValueListenableBuilder(
|
||||
valueListenable: Hive.box<PizzaRecipe>("PizzaRecipes").listenable(),
|
||||
valueListenable: Hive.box<PizzaRecipe>(PizzaRecipe.hiveName).listenable(),
|
||||
builder: (context, Box<PizzaRecipe> pizzaRecipesBox, widget) {
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.all(8),
|
||||
|
|
|
@ -39,7 +39,7 @@ class PizzaEventNotificationState extends State<PizzaEventNotificationPage> {
|
|||
final pizzaEventId = int.parse(split[0]);
|
||||
final recipeStepId = int.parse(split[1]);
|
||||
|
||||
final pizzaEventsBox = Hive.box<PizzaEvent>("PizzaEvents");
|
||||
final pizzaEventsBox = Hive.box<PizzaEvent>(PizzaEvent.hiveName);
|
||||
|
||||
pizzaEvent = pizzaEventsBox.get(pizzaEventId)!;
|
||||
recipeStep = pizzaEvent.recipe.recipeSteps[recipeStepId];
|
||||
|
|
|
@ -25,7 +25,7 @@ class PizzaEventsState extends State<PizzaEventsPage> {
|
|||
return PizzaPlannerScaffold(
|
||||
title: const Text("Pizza Events"),
|
||||
body: ValueListenableBuilder(
|
||||
valueListenable: Hive.box<PizzaEvent>("PizzaEvents").listenable(),
|
||||
valueListenable: Hive.box<PizzaEvent>(PizzaEvent.hiveName).listenable(),
|
||||
builder: (context, Box<PizzaEvent> pizzaEventBox, widget) {
|
||||
if (pizzaEventBox.isEmpty){
|
||||
return Container();
|
||||
|
|
|
@ -49,7 +49,7 @@ class RecipesPageState extends State<RecipesPage> {
|
|||
Expanded(
|
||||
flex: 50,
|
||||
child: ValueListenableBuilder(
|
||||
valueListenable: Hive.box<PizzaRecipe>("PizzaRecipes").listenable(),
|
||||
valueListenable: Hive.box<PizzaRecipe>(PizzaRecipe.hiveName).listenable(),
|
||||
builder: (context, Box<PizzaRecipe> pizzaRecipesBox, widget) {
|
||||
return ListView.separated(
|
||||
itemCount: pizzaRecipesBox.length,
|
||||
|
@ -220,7 +220,7 @@ class RecipesPageState extends State<RecipesPage> {
|
|||
try {
|
||||
File(result.files.single.path).readAsString().then((String contents) async {
|
||||
final pizzaRecipe = await PizzaRecipe.fromYaml(contents);
|
||||
final pizzaRecipeBox = Hive.box<PizzaRecipe>("PizzaRecipes");
|
||||
final pizzaRecipeBox = Hive.box<PizzaRecipe>(PizzaRecipe.hiveName);
|
||||
pizzaRecipeBox.add(pizzaRecipe);
|
||||
});
|
||||
} catch (exception) {
|
||||
|
|
1
todo.md
1
todo.md
|
@ -12,6 +12,5 @@
|
|||
## Refactor
|
||||
- RecipeStep.waitUnit should probably be an enum?
|
||||
- refactor to const page names instead of loose strings everywhere ('/path/page')
|
||||
- also do this with hive box names
|
||||
|
||||
## Bug
|
Loading…
Add table
Reference in a new issue