From 57ce64fc2bd2d9a8b028f190bf6173170cccd095 Mon Sep 17 00:00:00 2001 From: broodjeaap89 Date: Fri, 24 Sep 2021 20:50:00 +0200 Subject: [PATCH] added page to view the archived pizza events --- lib/main.dart | 4 ++ lib/pages/archived_pizza_event_page.dart | 74 ++++++++++++++++++++++++ lib/pages/nav_drawer.dart | 8 +++ todo.md | 1 - 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 lib/pages/archived_pizza_event_page.dart diff --git a/lib/main.dart b/lib/main.dart index cbf55e4..9c4946b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,6 +8,7 @@ import 'package:pizzaplanner/entities/PizzaRecipe/recipe_step.dart'; import 'package:pizzaplanner/entities/PizzaRecipe/recipe_substep.dart'; import 'package:pizzaplanner/pages/add_pizza_event_page.dart'; import 'package:pizzaplanner/pages/add_recipe_url.dart'; +import 'package:pizzaplanner/pages/archived_pizza_event_page.dart'; import 'package:pizzaplanner/pages/edit_recipe_page.dart'; import 'package:pizzaplanner/pages/edit_recipe_step_page.dart'; import 'package:pizzaplanner/pages/edit_recipe_sub_step_page.dart'; @@ -126,6 +127,9 @@ class RouteGenerator { case PizzaEventsPage.route: { return MaterialPageRoute(builder: (context) => PizzaEventsPage()); } + case ArchivedPizzaEventsPage.route: { + return MaterialPageRoute(builder: (context) => ArchivedPizzaEventsPage()); + } case PickPizzaRecipePage.route: { return MaterialPageRoute(builder: (context) => PickPizzaRecipePage()); } diff --git a/lib/pages/archived_pizza_event_page.dart b/lib/pages/archived_pizza_event_page.dart new file mode 100644 index 0000000..c11502d --- /dev/null +++ b/lib/pages/archived_pizza_event_page.dart @@ -0,0 +1,74 @@ +import 'package:flutter/material.dart'; +import 'package:hive_flutter/hive_flutter.dart'; +import 'package:pizzaplanner/entities/pizza_event.dart'; +import 'package:pizzaplanner/pages/pizza_event_page.dart'; +import 'package:pizzaplanner/pages/scaffold.dart'; +import 'package:pizzaplanner/widgets/pizza_event_widget.dart'; + +class ArchivedPizzaEventsPage extends StatefulWidget { + static const String route = "/events/archived"; + + @override + ArchivedPizzaEventsPageState createState() => ArchivedPizzaEventsPageState(); +} + +class ArchivedPizzaEventsPageState extends State { + @override + Widget build(BuildContext context){ + return PizzaPlannerScaffold( + title: const Text("Archived Pizza Events"), + body: ValueListenableBuilder( + valueListenable: Hive.box(PizzaEvent.hiveName).listenable(), + builder: (context, Box pizzaEventBox, widget) { + if (pizzaEventBox.isEmpty){ + return Container(); + } + return ListView.separated( + padding: const EdgeInsets.all(8), + itemCount: pizzaEventBox.length, + itemBuilder: (BuildContext context, int i) { + final pizzaEvent = pizzaEventBox.get(i); + if (pizzaEvent == null || !pizzaEvent.archived || pizzaEvent.deleted){ + return const SizedBox(); + } + return InkWell( + onTap: () { + showDialog(context: context, builder: (BuildContext context) { + return AlertDialog( + title: Text(pizzaEvent.name), + content: const Text("Remove from archive?"), + actions: [ + TextButton( + onPressed: () async { + Navigator.pop(context); + pizzaEvent.archived = false; + await pizzaEvent.save(); + }, + child: const Text("Yes"), + ), + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: const Text("No"), + ) + ] + ); + }); + }, + child: PizzaEventWidget(pizzaEvent), + ); + }, + separatorBuilder: (BuildContext context, int i) { + final pizzaEvent = pizzaEventBox.get(i); + if (pizzaEvent == null || !pizzaEvent.archived || pizzaEvent.deleted){ + return const SizedBox(); + } + return const Divider(); + }, + ); + } + ), + ); + } +} \ No newline at end of file diff --git a/lib/pages/nav_drawer.dart b/lib/pages/nav_drawer.dart index 32a7a65..84cb16a 100644 --- a/lib/pages/nav_drawer.dart +++ b/lib/pages/nav_drawer.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:pizzaplanner/entities/pizza_event.dart'; +import 'package:pizzaplanner/pages/archived_pizza_event_page.dart'; import 'package:pizzaplanner/pages/pizza_events_page.dart'; import 'package:pizzaplanner/pages/recipes_page.dart'; @@ -38,6 +39,13 @@ class NavDrawer extends StatelessWidget { Navigator.pushNamed(context, RecipesPage.route) }, ), + ListTile( + leading: const Icon(FontAwesome5.archive), + title: const Text("Archive"), + onTap: () => { + Navigator.pushNamed(context, ArchivedPizzaEventsPage.route) + }, + ), ] ) ); diff --git a/todo.md b/todo.md index 5365228..3ebfc09 100644 --- a/todo.md +++ b/todo.md @@ -1,7 +1,6 @@ # TODO ## Feature -- add page for archived pizza events? - add 'capturing' sharing intent - add settings page - option for type of notification, full screen or just in the appbar