From e388a7140e81fb930027507f91166f81080937a4 Mon Sep 17 00:00:00 2001 From: broodjeaap89 Date: Fri, 3 Sep 2021 17:54:40 +0200 Subject: [PATCH] fixed linting warnings in the rest of the dart code --- lib/pages/pick_pizza_recipe_page.dart | 4 +- lib/pages/pizza_event_notification_page.dart | 50 +++++++++--------- lib/pages/pizza_event_page.dart | 42 +++++++-------- lib/pages/pizza_events_page.dart | 10 ++-- lib/pages/recipe_step_instruction_page.dart | 54 ++++++++++---------- lib/widgets/pizza_event_widget.dart | 17 +++--- lib/widgets/pizza_recipe_widget.dart | 8 +-- 7 files changed, 91 insertions(+), 94 deletions(-) diff --git a/lib/pages/pick_pizza_recipe_page.dart b/lib/pages/pick_pizza_recipe_page.dart index ea66253..90c7abd 100644 --- a/lib/pages/pick_pizza_recipe_page.dart +++ b/lib/pages/pick_pizza_recipe_page.dart @@ -8,11 +8,11 @@ class PickPizzaRecipePage extends StatelessWidget { Widget build(BuildContext context){ return Scaffold( appBar: AppBar( - title: Text("Pick Pizza Recipe"), + title: const Text("Pick Pizza Recipe"), ), resizeToAvoidBottomInset: false, body: Container( - padding: EdgeInsets.fromLTRB(10, 10, 10, 10), + padding: const EdgeInsets.all(16), child: ValueListenableBuilder( valueListenable: Hive.box("PizzaRecipes").listenable(), builder: (context, Box pizzaRecipesBox, widget) { diff --git a/lib/pages/pizza_event_notification_page.dart b/lib/pages/pizza_event_notification_page.dart index 807df85..f42fcf9 100644 --- a/lib/pages/pizza_event_notification_page.dart +++ b/lib/pages/pizza_event_notification_page.dart @@ -18,7 +18,7 @@ import 'package:vibration/vibration.dart'; class PizzaEventNotificationPage extends StatefulWidget { final String? payload; - PizzaEventNotificationPage(this.payload); + const PizzaEventNotificationPage(this.payload); @override PizzaEventNotificationState createState() => PizzaEventNotificationState(); @@ -31,15 +31,14 @@ class PizzaEventNotificationState extends State { @override void initState() { super.initState(); - if (this.widget.payload == null){ - print("Redirected to notification page but no payload... Popping"); + if (widget.payload == null){ Navigator.pop(context); } - var split = this.widget.payload!.split("__"); - var pizzaEventId = int.parse(split[0]); - var recipeStepId = int.parse(split[1]); + final split = widget.payload!.split("__"); + final pizzaEventId = int.parse(split[0]); + final recipeStepId = int.parse(split[1]); - var pizzaEventsBox = Hive.box("PizzaEvents"); + final pizzaEventsBox = Hive.box("PizzaEvents"); pizzaEvent = pizzaEventsBox.get(pizzaEventId)!; recipeStep = pizzaEvent.recipe.recipeSteps[recipeStepId]; @@ -59,11 +58,11 @@ class PizzaEventNotificationState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text("From notification"), + title: const Text("From notification"), ), resizeToAvoidBottomInset: false, body: Container( - padding: EdgeInsets.fromLTRB(40, 10, 40, 10), + padding: const EdgeInsets.all(16), child: Column( children: [ Expanded( @@ -78,61 +77,59 @@ class PizzaEventNotificationState extends State { child: Text(recipeStep.name) ), ), - Divider(), + const Divider(), Expanded( flex: 10, child: Container( color: Colors.blue, width: double.infinity, child: TextButton( - child: Text("Ignore", style: TextStyle(color: Colors.white)), onPressed: () async { showDialog(context: context, builder: (BuildContext context) { return buildIgnoreDialog(); }); }, + child: const Text("Ignore", style: TextStyle(color: Colors.white)), ) ) ), - Divider(), + const Divider(), Expanded( flex: 30, child: Container( color: Colors.blue, width: double.infinity, child: TextButton( - child: Text("Snooze 15 minutes", style: TextStyle(color: Colors.white)), onPressed: () async { - setRecipeStepNotificatcion(DateTime.now().add(const Duration(minutes: 15))); + setRecipeStepNotification(DateTime.now().add(const Duration(minutes: 15))); Navigator.pop(context); }, onLongPress: () async { - var future5Min = DateTime.now().add(Duration(minutes: 5)); + final future5Min = DateTime.now().add(const Duration(minutes: 5)); DatePicker.showDateTimePicker(context, - showTitleActions: true, minTime: future5Min, currentTime: future5Min, - maxTime: DateTime.now().add(Duration(days: 365*10)), + maxTime: DateTime.now().add(const Duration(days: 365*10)), onConfirm: (newEventTime) { setState((){ - setRecipeStepNotificatcion(newEventTime); + setRecipeStepNotification(newEventTime); Navigator.pop(context); }); } ); }, + child: const Text("Snooze 15 minutes", style: TextStyle(color: Colors.white)), ) ) ), - Divider(), + const Divider(), Expanded( flex: 40, child: Container( color: Colors.blue, width: double.infinity, child: TextButton( - child: Text("Start!", style: TextStyle(color: Colors.white)), onPressed: () async { Navigator.pop(context); Navigator.pushNamed( @@ -144,6 +141,7 @@ class PizzaEventNotificationState extends State { ) ); }, + child: const Text("Start!", style: TextStyle(color: Colors.white)), ) ) ), @@ -162,17 +160,16 @@ class PizzaEventNotificationState extends State { AlertDialog buildIgnoreDialog(){ return AlertDialog( - title: Text("This step will be marked as completed."), - content: Text("Instructions for this step can still be viewed on the Pizza Event page"), + title: const Text("This step will be marked as completed."), + content: const Text("Instructions for this step can still be viewed on the Pizza Event page"), actions: [ TextButton( - child: Text("Back"), onPressed: () { Navigator.pop(context); }, + child: const Text("Back"), ), TextButton( - child: Text("Complete"), onPressed: () { setState(() { recipeStep.completeStepNow(); @@ -181,12 +178,13 @@ class PizzaEventNotificationState extends State { Navigator.pop(context); Navigator.pop(context); }, + child: const Text("Complete"), ), ] ); } - void setRecipeStepNotificatcion(DateTime newTime) async { + Future setRecipeStepNotification(DateTime newTime) async { flutterLocalNotificationsPlugin.cancel(recipeStep.notificationId); const androidPlatformChannelSpecifics = AndroidNotificationDetails( @@ -205,7 +203,7 @@ class PizzaEventNotificationState extends State { tz.TZDateTime.from(newTime, tz.local), platformChannelSpecific, androidAllowWhileIdle: true, - payload: this.widget.payload, + payload: widget.payload, uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime ); diff --git a/lib/pages/pizza_event_page.dart b/lib/pages/pizza_event_page.dart index 7e6ba21..9a1568d 100644 --- a/lib/pages/pizza_event_page.dart +++ b/lib/pages/pizza_event_page.dart @@ -14,7 +14,7 @@ import 'package:url_launcher/url_launcher.dart'; class PizzaEventPage extends StatefulWidget { final PizzaEvent pizzaEvent; - PizzaEventPage(this.pizzaEvent); + const PizzaEventPage(this.pizzaEvent); @override PizzaEventPageState createState() => PizzaEventPageState(); @@ -24,76 +24,76 @@ class PizzaEventPageState extends State { @override Widget build(BuildContext context) { - var recipeStepCount = this.widget.pizzaEvent.recipe.recipeSteps.length; - var completedRecipeStepCount = this.widget.pizzaEvent.recipe.recipeSteps.where((recipeStep) => recipeStep.completed).length; + final recipeStepCount = widget.pizzaEvent.recipe.recipeSteps.length; + final completedRecipeStepCount = widget.pizzaEvent.recipe.recipeSteps.where((recipeStep) => recipeStep.completed).length; return Scaffold( appBar: AppBar( - title: Text(this.widget.pizzaEvent.name), + title: Text(widget.pizzaEvent.name), ), resizeToAvoidBottomInset: false, body: Container( - padding: EdgeInsets.all(10), + padding: const EdgeInsets.all(16), child: Column( children: [ Expanded( flex: 15, child: Column( children: [ - Text(this.widget.pizzaEvent.name), - Text(getTimeRemainingString(this.widget.pizzaEvent.dateTime)), + Text(widget.pizzaEvent.name), + Text(getTimeRemainingString(widget.pizzaEvent.dateTime)), Container( color: Colors.blue, child: TextButton( - child: Text(this.widget.pizzaEvent.recipe.name, style: TextStyle(color: Colors.white)), onPressed: () { - Navigator.pushNamed(context, "/event/recipe", arguments: this.widget.pizzaEvent); + Navigator.pushNamed(context, "/event/recipe", arguments: widget.pizzaEvent); }, + child: Text(widget.pizzaEvent.recipe.name, style: const TextStyle(color: Colors.white)), ) ) ], ), ), - Divider(), + const Divider(), Expanded( flex: 80, child: ListView( children: [ - Center( + const Center( child: Text("Ingredients") ), Table( columnWidths: const { 0: FlexColumnWidth(4), 1: FlexColumnWidth(3), - 3: FlexColumnWidth(1), + 3: FlexColumnWidth(), }, children: [ - TableRow( + const TableRow( children: [ TableCell(child: Text("Ingredient")), TableCell(child: Text("Total")), TableCell(child: Center(child: Text("Bought"))) ] ) - ] + this.widget.pizzaEvent.recipe.ingredients.map((ingredient) => buildIngredientWidget(ingredient)).toList(), + ] + widget.pizzaEvent.recipe.ingredients.map((ingredient) => buildIngredientWidget(ingredient)).toList(), ), Table( columnWidths: const { 0: FlexColumnWidth(4), 1: FlexColumnWidth(3), - 2: FlexColumnWidth(1), + 2: FlexColumnWidth(), }, children: [ TableRow( children: [ - TableCell(child: Text("Recipe Step")), - TableCell(child: Text("When")), + const TableCell(child: Text("Recipe Step")), + const TableCell(child: Text("When")), TableCell(child: Text("$completedRecipeStepCount/$recipeStepCount")), ] ) - ] + this.widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => buildRecipeStepWhenWidget(recipeStep)).toList() + ] + widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => buildRecipeStepWhenWidget(recipeStep)).toList() ), - Divider(), + const Divider(), ] ) ), @@ -104,7 +104,7 @@ class PizzaEventPageState extends State { } TableRow buildIngredientWidget(Ingredient ingredient){ - int totalWeight = this.widget.pizzaEvent.pizzaCount * this.widget.pizzaEvent.doughBallSize; + final int totalWeight = widget.pizzaEvent.pizzaCount * widget.pizzaEvent.doughBallSize; return TableRow( children: [ TableCell(child: Text(ingredient.name)), @@ -113,7 +113,7 @@ class PizzaEventPageState extends State { value: ingredient.bought, onChanged: (bool? newValue) { setState((){ingredient.bought = newValue!;}); - this.widget.pizzaEvent.save(); + widget.pizzaEvent.save(); }, ))), ] diff --git a/lib/pages/pizza_events_page.dart b/lib/pages/pizza_events_page.dart index 975ff4f..7252c20 100644 --- a/lib/pages/pizza_events_page.dart +++ b/lib/pages/pizza_events_page.dart @@ -19,10 +19,10 @@ class PizzaEventsState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text("Pizza Events"), + title: const Text("Pizza Events"), ), body: Container( - padding: EdgeInsets.all(10), + padding: const EdgeInsets.all(16), child: ValueListenableBuilder( valueListenable: Hive.box("PizzaEvents").listenable(), builder: (context, Box box, widget) { @@ -46,13 +46,13 @@ class PizzaEventsState extends State { ); if (newPizzaEvent != null){ - this.addPizzaEvent(newPizzaEvent as PizzaEvent); + addPizzaEvent(newPizzaEvent as PizzaEvent); } }, tooltip: "Add Pizza Plans", child: Center( child: Row( - children: [ + children: const [ Icon(Icons.add), Icon(Icons.local_pizza_rounded), ] @@ -63,7 +63,7 @@ class PizzaEventsState extends State { } void addPizzaEvent(PizzaEvent pizzaEvent){ - this.setState(() { + setState(() { pizzaEvents.add( pizzaEvent ); diff --git a/lib/pages/recipe_step_instruction_page.dart b/lib/pages/recipe_step_instruction_page.dart index fe4f055..3268850 100644 --- a/lib/pages/recipe_step_instruction_page.dart +++ b/lib/pages/recipe_step_instruction_page.dart @@ -18,8 +18,8 @@ class RecipeStepInstructionPage extends StatefulWidget { late final RecipeStep recipeStep; RecipeStepInstructionPage(RecipeStepInstructionPageArguments arguments) { - this.pizzaEvent = arguments.pizzaEvent; - this.recipeStep = arguments.recipeStep; + pizzaEvent = arguments.pizzaEvent; + recipeStep = arguments.recipeStep; } @@ -36,46 +36,46 @@ class RecipeStepInstructionState extends State { void initState() { super.initState(); - if (this.widget.recipeStep.subSteps.isNotEmpty) { - this.currentSubStep = this.widget.recipeStep.subSteps.first; + if (widget.recipeStep.subSteps.isNotEmpty) { + currentSubStep = widget.recipeStep.subSteps.first; } } @override Widget build(BuildContext context) { var nextButtonText = "Start"; - if (this.page == this.widget.recipeStep.subSteps.length){ // -1 because of description page + if (page == widget.recipeStep.subSteps.length){ // -1 because of description page nextButtonText = "Finished"; - } else if (this.page > 0){ + } else if (page > 0){ nextButtonText = "Next step"; } return Scaffold( appBar: AppBar( - title: Text(this.widget.recipeStep.name), + title: Text(widget.recipeStep.name), ), resizeToAvoidBottomInset: false, body: Container( - padding: EdgeInsets.all(16), + padding: const EdgeInsets.all(16), child: Column( children: [ Expanded( flex: 90, child: PageView( - controller: this.controller, + controller: controller, onPageChanged: (newPage) => setState(() { - this.page = newPage; - if (this.widget.recipeStep.subSteps.isNotEmpty && this.page != 0) { - this.currentSubStep = this.widget.recipeStep.subSteps.elementAt(newPage-1); + page = newPage; + if (widget.recipeStep.subSteps.isNotEmpty && page != 0) { + currentSubStep = widget.recipeStep.subSteps.elementAt(newPage-1); } }), children: [ Markdown( - data: this.widget.recipeStep.description, + data: widget.recipeStep.description, onTapLink: (text, url, title) { launch(url!); }, ) - ] + this.widget.recipeStep.subSteps.map((subStep) { + ] + widget.recipeStep.subSteps.map((subStep) { return Markdown( data: subStep.description, onTapLink: (text, url, title) { @@ -95,17 +95,17 @@ class RecipeStepInstructionState extends State { width: double.infinity, color: Colors.blue, child: TextButton( - child: Text("Back", style: TextStyle(color: Colors.white)), onPressed: () { if (page == 0){ return; } - if (this.currentSubStep != null){ - this.currentSubStep?.completedOn = null; - this.widget.pizzaEvent.save(); + if (currentSubStep != null){ + currentSubStep?.completedOn = null; + widget.pizzaEvent.save(); } - this.controller.previousPage(duration: const Duration(milliseconds: 100), curve: Curves.ease); + controller.previousPage(duration: const Duration(milliseconds: 100), curve: Curves.ease); }, + child: const Text("Back", style: TextStyle(color: Colors.white)), ) ) ), @@ -119,19 +119,19 @@ class RecipeStepInstructionState extends State { width: double.infinity, color: Colors.blue, child: TextButton( - child: Text(nextButtonText, style: TextStyle(color: Colors.white)), onPressed: () { - if (this.page == this.widget.recipeStep.subSteps.length){ - this.widget.recipeStep.completeStepNow(); - this.widget.pizzaEvent.save(); + if (page == widget.recipeStep.subSteps.length){ + widget.recipeStep.completeStepNow(); + widget.pizzaEvent.save(); Navigator.pop(context); return; - } else if (this.currentSubStep != null){ - this.currentSubStep?.completeNow(); - this.widget.pizzaEvent.save(); + } else if (currentSubStep != null){ + currentSubStep?.completeNow(); + widget.pizzaEvent.save(); } - this.controller.nextPage(duration: const Duration(milliseconds: 100), curve: Curves.ease); + controller.nextPage(duration: const Duration(milliseconds: 100), curve: Curves.ease); }, + child: Text(nextButtonText, style: const TextStyle(color: Colors.white)), ) ) ), diff --git a/lib/widgets/pizza_event_widget.dart b/lib/widgets/pizza_event_widget.dart index 4a084bc..50aaca0 100644 --- a/lib/widgets/pizza_event_widget.dart +++ b/lib/widgets/pizza_event_widget.dart @@ -5,11 +5,18 @@ import 'package:pizzaplanner/util.dart'; class PizzaEventWidget extends StatelessWidget { final PizzaEvent pizzaEvent; - PizzaEventWidget(this.pizzaEvent); + const PizzaEventWidget(this.pizzaEvent); @override Widget build(BuildContext context){ return InkWell( + onTap: () { + Navigator.pushNamed( + context, + "/event/view", + arguments: pizzaEvent + ); + }, child: Container( height: 120, color: Colors.blueAccent, @@ -34,7 +41,6 @@ class PizzaEventWidget extends StatelessWidget { Expanded( child: IgnorePointer( child: Slider( - min: 0.0, max: pizzaEvent.recipe.recipeSteps.length.toDouble(), divisions: pizzaEvent.recipe.recipeSteps.length, value: pizzaEvent.recipe.getStepsCompleted().toDouble(), @@ -59,13 +65,6 @@ class PizzaEventWidget extends StatelessWidget { ) ) ), - onTap: () { - Navigator.pushNamed( - context, - "/event/view", - arguments: this.pizzaEvent - ); - }, ); } } \ No newline at end of file diff --git a/lib/widgets/pizza_recipe_widget.dart b/lib/widgets/pizza_recipe_widget.dart index d9dd342..6190d86 100644 --- a/lib/widgets/pizza_recipe_widget.dart +++ b/lib/widgets/pizza_recipe_widget.dart @@ -4,11 +4,14 @@ import 'package:pizzaplanner/entities/PizzaRecipe/pizza_recipe.dart'; class PizzaRecipeWidget extends StatelessWidget { final PizzaRecipe pizzaRecipe; - PizzaRecipeWidget(this.pizzaRecipe); + const PizzaRecipeWidget(this.pizzaRecipe); @override Widget build(BuildContext context) { return InkWell( + onTap: () { + Navigator.pushNamed(context, "/event/add", arguments: this.pizzaRecipe); + }, child: Container( height: 120, color: Colors.blueAccent, @@ -34,9 +37,6 @@ class PizzaRecipeWidget extends StatelessWidget { ) ) ), - onTap: () { - Navigator.pushNamed(context, "/event/add", arguments: this.pizzaRecipe); - }, ); } } \ No newline at end of file