switched to static const strings for route names on each page class
This commit is contained in:
parent
0a18438659
commit
0d9fc454d4
14 changed files with 61 additions and 35 deletions
|
@ -72,10 +72,10 @@ Future<void> main() async {
|
|||
tz.setLocalLocation(tz.getLocation(timeZoneName));
|
||||
|
||||
final NotificationAppLaunchDetails? notificationAppLaunchDetails = await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();
|
||||
String initialRoute = "/";
|
||||
String initialRoute = PizzaEventsPage.route;
|
||||
if (notificationAppLaunchDetails?.didNotificationLaunchApp ?? false) {
|
||||
selectedNotificationPayload = notificationAppLaunchDetails!.payload;
|
||||
initialRoute = "/event/notification";
|
||||
initialRoute = PizzaEventNotificationPage.route;
|
||||
}
|
||||
|
||||
runApp(PizzaPlanner(initialRoute));
|
||||
|
@ -116,7 +116,7 @@ class PizzaPlannerState extends State<PizzaPlanner> {
|
|||
|
||||
void _configureSelectNotificationSubject() {
|
||||
selectNotificationSubject.stream.listen((String? payload) async {
|
||||
await navigatorKey.currentState?.pushNamed('/event/notification', arguments: payload);
|
||||
await navigatorKey.currentState?.pushNamed(PizzaEventNotificationPage.route, arguments: payload);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -124,71 +124,69 @@ class PizzaPlannerState extends State<PizzaPlanner> {
|
|||
class RouteGenerator {
|
||||
static Route<dynamic> generateRoute(RouteSettings settings){
|
||||
switch(settings.name){
|
||||
case "/": {
|
||||
case PizzaEventsPage.route: {
|
||||
return MaterialPageRoute(builder: (context) => PizzaEventsPage());
|
||||
}
|
||||
case "/event/pick_recipe": {
|
||||
case PickPizzaRecipePage.route: {
|
||||
return MaterialPageRoute(builder: (context) => PickPizzaRecipePage());
|
||||
}
|
||||
case "/event/add": {
|
||||
case AddPizzaEventPage.route: {
|
||||
final pizzaRecipe = settings.arguments as PizzaRecipe?;
|
||||
if (pizzaRecipe == null){
|
||||
break;
|
||||
}
|
||||
return MaterialPageRoute(builder: (context) => AddPizzaEventPage(pizzaRecipe));
|
||||
}
|
||||
case "/event/view": {
|
||||
case PizzaEventPage.route: {
|
||||
final pizzaEvent = settings.arguments as PizzaEvent?;
|
||||
if (pizzaEvent == null){
|
||||
break;
|
||||
}
|
||||
return MaterialPageRoute(builder: (context) => PizzaEventPage(pizzaEvent));
|
||||
}
|
||||
case "/recipe/view": {
|
||||
case RecipePage.route: {
|
||||
final pizzaRecipe = settings.arguments as PizzaRecipe?;
|
||||
if (pizzaRecipe == null){
|
||||
break;
|
||||
}
|
||||
return MaterialPageRoute(builder: (context) => RecipePage(pizzaRecipe));
|
||||
}
|
||||
case "/event/notification": {
|
||||
case PizzaEventNotificationPage.route: {
|
||||
if (selectedNotificationPayload != null) {
|
||||
return MaterialPageRoute(builder: (context) => PizzaEventNotificationPage(selectedNotificationPayload));
|
||||
} else if (settings.arguments != null) {
|
||||
|
||||
return MaterialPageRoute(builder: (context) => PizzaEventNotificationPage(settings.arguments as String?));
|
||||
} else {
|
||||
return MaterialPageRoute(builder: (context) => PizzaEventsPage());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "/event/recipe_step": {
|
||||
case RecipeStepInstructionPage.route: {
|
||||
final recipeStepInstructionArgument = settings.arguments as RecipeStepInstructionPageArguments?;
|
||||
if (recipeStepInstructionArgument == null){
|
||||
break;
|
||||
}
|
||||
return MaterialPageRoute(builder: (context) => RecipeStepInstructionPage(recipeStepInstructionArgument));
|
||||
}
|
||||
case "/recipes/view": {
|
||||
case RecipesPage.route: {
|
||||
return MaterialPageRoute(builder: (context) => RecipesPage());
|
||||
}
|
||||
case "/recipes/edit": {
|
||||
case EditRecipePage.route: {
|
||||
return MaterialPageRoute(builder: (context) => EditRecipePage(pizzaRecipe: settings.arguments as PizzaRecipe?));
|
||||
}
|
||||
case "/recipes/add/edit_step": {
|
||||
case EditRecipeStepPage.route: {
|
||||
final recipeStep = settings.arguments as RecipeStep?;
|
||||
if(recipeStep == null){
|
||||
break;
|
||||
}
|
||||
return MaterialPageRoute(builder: (context) => EditRecipeStepPage(recipeStep));
|
||||
}
|
||||
case "/recipes/add/edit_sub_step": {
|
||||
case EditRecipeSubStepPage.route: {
|
||||
final subStep = settings.arguments as RecipeSubStep?;
|
||||
if(subStep == null){
|
||||
break;
|
||||
}
|
||||
return MaterialPageRoute(builder: (context) => EditRecipeSubStepPage(subStep));
|
||||
}
|
||||
case "/recipes/add/url": {
|
||||
case AddRecipeURLPage.route: {
|
||||
return MaterialPageRoute(builder: (context) => AddRecipeURLPage(settings.arguments as String?));
|
||||
}
|
||||
default: {
|
||||
|
|
|
@ -14,6 +14,7 @@ import 'package:hive/hive.dart';
|
|||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
|
||||
class AddPizzaEventPage extends StatefulWidget {
|
||||
static const String route = "/event/add";
|
||||
final PizzaRecipe pizzaRecipe;
|
||||
|
||||
const AddPizzaEventPage(this.pizzaRecipe);
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/pizza_recipe.dart';
|
||||
import 'package:pizzaplanner/pages/recipe_page.dart';
|
||||
import 'package:pizzaplanner/pages/scaffold.dart';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
@ -9,6 +10,7 @@ import 'package:pizzaplanner/widgets/pizza_recipe_widget.dart';
|
|||
import 'package:yaml/yaml.dart';
|
||||
|
||||
class AddRecipeURLPage extends StatefulWidget {
|
||||
static const String route = "/recipes/add/url";
|
||||
final String? url;
|
||||
|
||||
const AddRecipeURLPage(this.url);
|
||||
|
@ -142,7 +144,7 @@ class AddRecipeURLPageState extends State<AddRecipeURLPage> {
|
|||
widgets.add(
|
||||
InkWell(
|
||||
onTap: () {
|
||||
Navigator.pushNamed(context, "/recipes/add/url", arguments: url);
|
||||
Navigator.pushNamed(context, AddRecipeURLPage.route, arguments: url);
|
||||
},
|
||||
child: Container(
|
||||
height: 70,
|
||||
|
@ -184,7 +186,7 @@ class AddRecipeURLPageState extends State<AddRecipeURLPage> {
|
|||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pushNamed(context, "/recipe/view", arguments: pizzaRecipe);
|
||||
Navigator.pushNamed(context, RecipePage.route, arguments: pizzaRecipe);
|
||||
},
|
||||
child: const Text("View"),
|
||||
),
|
||||
|
|
|
@ -5,10 +5,12 @@ import 'package:pizzaplanner/entities/PizzaRecipe/ingredient.dart';
|
|||
import 'package:pizzaplanner/entities/PizzaRecipe/pizza_recipe.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/recipe_step.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/recipe_substep.dart';
|
||||
import 'package:pizzaplanner/pages/edit_recipe_step_page.dart';
|
||||
import 'package:pizzaplanner/pages/scaffold.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class EditRecipePage extends StatefulWidget {
|
||||
static const String route = "/recipes/edit";
|
||||
late final PizzaRecipe? _pizzaRecipe;
|
||||
|
||||
EditRecipePage({PizzaRecipe? pizzaRecipe}){
|
||||
|
@ -289,7 +291,7 @@ class EditRecipePageState extends State<EditRecipePage> {
|
|||
child: TextButton(
|
||||
onPressed: () {
|
||||
FocusScope.of(context).unfocus();
|
||||
Navigator.pushNamed(context, "/recipes/add/edit_step", arguments: recipeStep).then(
|
||||
Navigator.pushNamed(context, EditRecipeStepPage.route, arguments: recipeStep).then(
|
||||
(_) {
|
||||
setState((){});
|
||||
}
|
||||
|
|
|
@ -3,11 +3,13 @@ import 'package:pizzaplanner/entities/PizzaRecipe/pizza_recipe.dart';
|
|||
import 'package:pizzaplanner/entities/PizzaRecipe/recipe_step.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/recipe_substep.dart';
|
||||
import 'package:pizzaplanner/pages/edit_recipe_page.dart';
|
||||
import 'package:pizzaplanner/pages/edit_recipe_sub_step_page.dart';
|
||||
import 'package:pizzaplanner/pages/nav_drawer.dart';
|
||||
import 'package:pizzaplanner/pages/scaffold.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class EditRecipeStepPage extends StatefulWidget {
|
||||
static const String route = "/recipes/add/edit_step";
|
||||
final RecipeStep recipeStep;
|
||||
|
||||
const EditRecipeStepPage(this.recipeStep);
|
||||
|
@ -189,7 +191,7 @@ class EditRecipeStepPageState extends State<EditRecipeStepPage> {
|
|||
child: TextButton(
|
||||
onPressed: () {
|
||||
FocusScope.of(context).unfocus();
|
||||
Navigator.pushNamed(context, "/recipes/add/edit_sub_step", arguments: subStep).then(
|
||||
Navigator.pushNamed(context, EditRecipeSubStepPage.route, arguments: subStep).then(
|
||||
(_) {
|
||||
setState((){});
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:pizzaplanner/pages/scaffold.dart';
|
|||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class EditRecipeSubStepPage extends StatefulWidget {
|
||||
static const String route = "/recipes/add/edit_sub_step";
|
||||
final RecipeSubStep subStep;
|
||||
|
||||
const EditRecipeSubStepPage(this.subStep);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttericon/font_awesome5_icons.dart';
|
||||
import 'package:pizzaplanner/pages/recipes_page.dart';
|
||||
|
||||
class NavDrawer extends StatelessWidget {
|
||||
@override
|
||||
|
@ -25,7 +26,7 @@ class NavDrawer extends StatelessWidget {
|
|||
leading: const Icon(FontAwesome5.pizza_slice),
|
||||
title: const Text("Recipes"),
|
||||
onTap: () => {
|
||||
Navigator.pushNamed(context, "/recipes/view")
|
||||
Navigator.pushNamed(context, RecipesPage.route)
|
||||
},
|
||||
)
|
||||
]
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:hive_flutter/adapters.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/pizza_recipe.dart';
|
||||
import 'package:pizzaplanner/pages/add_pizza_event_page.dart';
|
||||
import 'package:pizzaplanner/pages/nav_drawer.dart';
|
||||
import 'package:pizzaplanner/pages/scaffold.dart';
|
||||
import 'package:pizzaplanner/widgets/pizza_recipe_widget.dart';
|
||||
|
||||
class PickPizzaRecipePage extends StatelessWidget {
|
||||
static const String route = "/event/pick_recipe";
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
return PizzaPlannerScaffold(
|
||||
|
@ -23,7 +26,7 @@ class PickPizzaRecipePage extends StatelessWidget {
|
|||
}
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Navigator.pushNamed(context, "/event/add", arguments: pizzaRecipe);
|
||||
Navigator.pushNamed(context, AddPizzaEventPage.route, arguments: pizzaRecipe);
|
||||
},
|
||||
child: PizzaRecipeWidget(pizzaRecipe),
|
||||
);
|
||||
|
|
|
@ -17,6 +17,7 @@ import 'package:vibration/vibration.dart';
|
|||
|
||||
|
||||
class PizzaEventNotificationPage extends StatefulWidget {
|
||||
static const String route = "/event/notification";
|
||||
final String? payload;
|
||||
|
||||
const PizzaEventNotificationPage(this.payload);
|
||||
|
@ -130,7 +131,7 @@ class PizzaEventNotificationState extends State<PizzaEventNotificationPage> {
|
|||
Navigator.pop(context);
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
"/event/recipe_step",
|
||||
RecipeStepInstructionPage.route,
|
||||
arguments: RecipeStepInstructionPageArguments(
|
||||
pizzaEvent,
|
||||
recipeStep
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:pizzaplanner/entities/PizzaRecipe/ingredient.dart';
|
|||
import 'package:pizzaplanner/entities/PizzaRecipe/recipe_step.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/recipe_substep.dart';
|
||||
import 'package:pizzaplanner/main.dart';
|
||||
import 'package:pizzaplanner/pages/recipe_page.dart';
|
||||
import 'package:pizzaplanner/pages/recipe_step_instruction_page.dart';
|
||||
import 'package:pizzaplanner/pages/scaffold.dart';
|
||||
import 'package:pizzaplanner/util.dart';
|
||||
|
@ -14,6 +15,8 @@ import 'package:pizzaplanner/widgets/pizza_recipe_widget.dart';
|
|||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class PizzaEventPage extends StatefulWidget {
|
||||
static const String route = "/event/view";
|
||||
|
||||
final PizzaEvent pizzaEvent;
|
||||
|
||||
const PizzaEventPage(this.pizzaEvent);
|
||||
|
@ -57,7 +60,7 @@ class PizzaEventPageState extends State<PizzaEventPage> {
|
|||
color: Colors.blue,
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, "/recipe/view", arguments: widget.pizzaEvent.recipe);
|
||||
Navigator.pushNamed(context, RecipePage.route, arguments: widget.pizzaEvent.recipe);
|
||||
},
|
||||
child: Text(widget.pizzaEvent.recipe.name, style: const TextStyle(color: Colors.white)),
|
||||
)
|
||||
|
@ -113,7 +116,7 @@ class PizzaEventPageState extends State<PizzaEventPage> {
|
|||
onPressed: () {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
"/event/recipe_step",
|
||||
RecipeStepInstructionPage.route,
|
||||
arguments: RecipeStepInstructionPageArguments(
|
||||
widget.pizzaEvent,
|
||||
firstStepDue!
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pizzaplanner/entities/pizza_event.dart';
|
||||
import 'package:pizzaplanner/pages/pick_pizza_recipe_page.dart';
|
||||
import 'package:pizzaplanner/pages/pizza_event_page.dart';
|
||||
import 'package:pizzaplanner/pages/scaffold.dart';
|
||||
import 'package:pizzaplanner/widgets/pizza_event_widget.dart';
|
||||
|
||||
|
@ -8,6 +10,8 @@ import 'package:hive/hive.dart';
|
|||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
|
||||
class PizzaEventsPage extends StatefulWidget {
|
||||
static const String route = "/";
|
||||
|
||||
@override
|
||||
PizzaEventsState createState() => PizzaEventsState();
|
||||
}
|
||||
|
@ -36,7 +40,7 @@ class PizzaEventsState extends State<PizzaEventsPage> {
|
|||
}
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Navigator.pushNamed(context, "/event/view", arguments: pizzaEvent);
|
||||
Navigator.pushNamed(context, PizzaEventPage.route, arguments: pizzaEvent);
|
||||
},
|
||||
onLongPress: () {
|
||||
showDialog(context: context, builder: (BuildContext context) {
|
||||
|
@ -47,7 +51,7 @@ class PizzaEventsState extends State<PizzaEventsPage> {
|
|||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pushNamed(context, "/event/view", arguments: pizzaEvent);
|
||||
Navigator.pushNamed(context, PizzaEventPage.route, arguments: pizzaEvent);
|
||||
},
|
||||
child: const Text("View"),
|
||||
),
|
||||
|
@ -111,7 +115,7 @@ class PizzaEventsState extends State<PizzaEventsPage> {
|
|||
onPressed: () async {
|
||||
final dynamic newPizzaEvent = await Navigator.pushNamed(
|
||||
context,
|
||||
"/event/pick_recipe",
|
||||
PickPizzaRecipePage.route,
|
||||
);
|
||||
|
||||
if (newPizzaEvent != null){
|
||||
|
|
|
@ -7,6 +7,8 @@ import 'package:pizzaplanner/pages/scaffold.dart';
|
|||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class RecipePage extends StatefulWidget {
|
||||
static const String route = "/recipe/view";
|
||||
|
||||
final PizzaRecipe pizzaRecipe;
|
||||
const RecipePage(this.pizzaRecipe);
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@ class RecipeStepInstructionPageArguments {
|
|||
}
|
||||
|
||||
class RecipeStepInstructionPage extends StatefulWidget {
|
||||
static const String route = "/event/recipe_step";
|
||||
|
||||
late final PizzaEvent pizzaEvent;
|
||||
late final RecipeStep recipeStep;
|
||||
|
||||
|
|
|
@ -5,7 +5,10 @@ import 'package:flutter/material.dart';
|
|||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/pizza_recipe.dart';
|
||||
import 'package:pizzaplanner/pages/add_recipe_url.dart';
|
||||
import 'package:pizzaplanner/pages/edit_recipe_page.dart';
|
||||
import 'package:pizzaplanner/pages/nav_drawer.dart';
|
||||
import 'package:pizzaplanner/pages/recipe_page.dart';
|
||||
import 'package:pizzaplanner/pages/scaffold.dart';
|
||||
import 'package:pizzaplanner/widgets/pizza_recipe_widget.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
@ -13,6 +16,7 @@ import 'package:share_plus/share_plus.dart';
|
|||
|
||||
|
||||
class RecipesPage extends StatefulWidget {
|
||||
static const String route = "/recipes/view";
|
||||
@override
|
||||
RecipesPageState createState() => RecipesPageState();
|
||||
}
|
||||
|
@ -61,7 +65,7 @@ class RecipesPageState extends State<RecipesPage> {
|
|||
return InkWell(
|
||||
onTap: () {
|
||||
FocusScope.of(context).unfocus();
|
||||
Navigator.pushNamed(context, "/recipe/view", arguments: pizzaRecipe);
|
||||
Navigator.pushNamed(context, RecipePage.route, arguments: pizzaRecipe);
|
||||
},
|
||||
onLongPress: () {
|
||||
FocusScope.of(context).unfocus();
|
||||
|
@ -80,14 +84,14 @@ class RecipesPageState extends State<RecipesPage> {
|
|||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pushNamed(context, "/recipe/view", arguments: pizzaRecipe);
|
||||
Navigator.pushNamed(context, RecipePage.route, arguments: pizzaRecipe);
|
||||
},
|
||||
child: const Text("View"),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pushNamed(context, "/recipes/edit", arguments: pizzaRecipe);
|
||||
Navigator.pushNamed(context, EditRecipePage.route, arguments: pizzaRecipe);
|
||||
},
|
||||
child: const Text("Edit"),
|
||||
),
|
||||
|
@ -170,7 +174,7 @@ class RecipesPageState extends State<RecipesPage> {
|
|||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pushNamed(context, "/recipes/add/url");
|
||||
Navigator.pushNamed(context, AddRecipeURLPage.route);
|
||||
},
|
||||
child: const Text("URL"),
|
||||
)
|
||||
|
@ -194,7 +198,7 @@ class RecipesPageState extends State<RecipesPage> {
|
|||
width: double.infinity,
|
||||
child: TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pushNamed(context, "/recipes/edit");
|
||||
Navigator.pushNamed(context, EditRecipePage.route);
|
||||
},
|
||||
child: const Text("New Recipe", style: TextStyle(color: Colors.white)),
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue