'fixed' deleting recipes in a hacky way, because of a bug in the Hive package ?
This commit is contained in:
parent
95c8516151
commit
5080945de6
2 changed files with 66 additions and 3 deletions
|
@ -23,6 +23,12 @@ class PizzaRecipe extends HiveObject {
|
||||||
|
|
||||||
@HiveField(3)
|
@HiveField(3)
|
||||||
List<RecipeStep> recipeSteps;
|
List<RecipeStep> recipeSteps;
|
||||||
|
|
||||||
|
// Using this because deleting it from the box does weird things.
|
||||||
|
// It seems to 'null' the item that you delete, and then reduce the size/length
|
||||||
|
// cutting off the last item
|
||||||
|
@HiveField(4)
|
||||||
|
bool deleted = false;
|
||||||
|
|
||||||
PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps);
|
PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps);
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ class RecipesPage extends StatelessWidget {
|
||||||
itemCount: pizzaRecipesBox.length,
|
itemCount: pizzaRecipesBox.length,
|
||||||
itemBuilder: (context, i) {
|
itemBuilder: (context, i) {
|
||||||
final pizzaRecipe = pizzaRecipesBox.get(i);
|
final pizzaRecipe = pizzaRecipesBox.get(i);
|
||||||
if (pizzaRecipe == null){
|
if (pizzaRecipe == null || pizzaRecipe.deleted){
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
}
|
}
|
||||||
return InkWell(
|
return InkWell(
|
||||||
|
@ -46,12 +46,69 @@ class RecipesPage extends StatelessWidget {
|
||||||
Navigator.pushNamed(context, "/recipe/view", arguments: pizzaRecipe);
|
Navigator.pushNamed(context, "/recipe/view", arguments: pizzaRecipe);
|
||||||
},
|
},
|
||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
Navigator.pushNamed(context, "/recipes/edit", arguments: pizzaRecipe);
|
showDialog(context: context, builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(pizzaRecipe.name),
|
||||||
|
content: const Text("What do you want to do?"),
|
||||||
|
actions: <Widget>[
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
Navigator.pushNamed(context, "/recipe/view", arguments: pizzaRecipe);
|
||||||
|
},
|
||||||
|
child: const Text("View"),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
Navigator.pushNamed(context, "/recipes/edit", arguments: pizzaRecipe);
|
||||||
|
},
|
||||||
|
child: const Text("Edit"),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
showDialog(context: context, builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text("Delete?"),
|
||||||
|
content: const Text("Are you sure?"),
|
||||||
|
actions: <Widget>[
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
child: const Text("Back"),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
if (pizzaRecipe.isInBox){
|
||||||
|
pizzaRecipe.deleted = true;
|
||||||
|
pizzaRecipe.save();
|
||||||
|
}
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
child: const Text("Delete", style: TextStyle(color: Colors.redAccent)),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: const Text("Delete", style: TextStyle(color: Colors.redAccent)),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
child: PizzaRecipeWidget(pizzaRecipe),
|
child: PizzaRecipeWidget(pizzaRecipe),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
separatorBuilder: (BuildContext context, int i) => const Divider(),
|
separatorBuilder: (BuildContext context, int i) {
|
||||||
|
final pizzaRecipe = pizzaRecipesBox.get(i);
|
||||||
|
if (pizzaRecipe == null || pizzaRecipe.deleted){
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
return const Divider();
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Reference in a new issue