diff --git a/lib/entities/PizzaRecipe/ingredient.dart b/lib/entities/PizzaRecipe/ingredient.dart index 1f09001..8c039c0 100644 --- a/lib/entities/PizzaRecipe/ingredient.dart +++ b/lib/entities/PizzaRecipe/ingredient.dart @@ -24,9 +24,9 @@ class Ingredient extends HiveObject { TableRow getIngredientTableRow(int pizzaCount, int doughBallSize){ return TableRow( children: [ - TableCell(child: Center(child: Text("${this.name.capitalize()}"))), - TableCell(child: Center(child: Text("${this.getAbsoluteString(doughBallSize)}$unit"))), - TableCell(child: Center(child: Text("${this.getAbsoluteString(pizzaCount * doughBallSize)}$unit"))), + TableCell(child: Center(child: Text(name.capitalize()))), + TableCell(child: Center(child: Text("${getAbsoluteString(doughBallSize)}$unit"))), + TableCell(child: Center(child: Text("${getAbsoluteString(pizzaCount * doughBallSize)}$unit"))), ], ); } diff --git a/lib/entities/PizzaRecipe/pizza_recipe.dart b/lib/entities/PizzaRecipe/pizza_recipe.dart index 8beeafc..a3ebfa5 100644 --- a/lib/entities/PizzaRecipe/pizza_recipe.dart +++ b/lib/entities/PizzaRecipe/pizza_recipe.dart @@ -27,26 +27,26 @@ class PizzaRecipe extends HiveObject { PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps); String getShortDescriptionString(){ - if (this.description.length < 150) { // TODO 150? - return this.description; + if (description.length < 150) { // TODO 150? + return description; } - var endOfLineIndex = this.description.indexOf(RegExp("[.]|\$")) + 1; + final endOfLineIndex = description.indexOf(RegExp("[.]|\$")) + 1; if (endOfLineIndex >= 150){ - var first150 = this.description.substring(0, 150); + final first150 = description.substring(0, 150); return "$first150..."; } - return this.description.substring(0, endOfLineIndex); + return description.substring(0, endOfLineIndex); } Table getIngredientsTable(int pizzaCount, int doughBallSize) { return Table( border: TableBorder.all(), columnWidths: const { 0: FlexColumnWidth(2), - 1: FlexColumnWidth(1), + 1: FlexColumnWidth(), 2: FlexColumnWidth(2), }, children: [ - TableRow( + const TableRow( children: [ TableCell(child: Center(child: Text("Ingredient"))), TableCell(child: Center(child: Text("Per Ball"))), @@ -63,7 +63,7 @@ class PizzaRecipe extends HiveObject { int getStepsCompleted(){ var stepCount = 0; - for (var recipeStep in this.recipeSteps) { + for (final recipeStep in recipeSteps) { if (!recipeStep.completed) { return stepCount; } @@ -73,27 +73,27 @@ class PizzaRecipe extends HiveObject { } static Future fromYaml(String yamlPath) async{ - String yamlString = await loadAsset(yamlPath); - var yaml = loadYaml(yamlString); - YamlMap recipe = yaml["recipe"] as YamlMap; + final String yamlString = await loadAsset(yamlPath); + final yaml = loadYaml(yamlString); + final YamlMap recipe = yaml["recipe"] as YamlMap; - String name = recipe["name"] as String; - String description = recipe["description"] as String; + final String name = recipe["name"] as String; + final String description = recipe["description"] as String; - YamlList ingredients = recipe["ingredients"] as YamlList; + final YamlList ingredients = recipe["ingredients"] as YamlList; - List newIngredients = ingredients.map( + final List newIngredients = ingredients.map( (ingredient) => Ingredient( ingredient["name"] as String, ingredient["unit"] as String, ingredient["value"] as double )).toList(); - YamlList steps = recipe["steps"] as YamlList; - var newRecipeSteps = List.generate(steps.length, (i) { - YamlMap step = steps[i] as YamlMap; - String stepName = step["name"] as String; - String stepDescription = step["description"] as String; + final YamlList steps = recipe["steps"] as YamlList; + final newRecipeSteps = List.generate(steps.length, (i) { + final YamlMap step = steps[i] as YamlMap; + final String stepName = step["name"] as String; + final String stepDescription = step["description"] as String; String waitUnit = "none"; String waitDescription = ""; @@ -101,7 +101,7 @@ class PizzaRecipe extends HiveObject { int waitMax = 0; if (step.containsKey("wait")) { - YamlMap waitMap = step["wait"] as YamlMap; + final YamlMap waitMap = step["wait"] as YamlMap; waitDescription = waitMap["description"] as String; waitUnit = waitMap["unit"] as String; @@ -109,9 +109,9 @@ class PizzaRecipe extends HiveObject { waitMax = waitMap["max"] as int; } - YamlList subSteps = step.containsKey("substeps") ? step["substeps"] as YamlList : YamlList(); - var newSubSteps = List.generate(subSteps.length, (j) { - var subStep = subSteps[j]; + final YamlList subSteps = step.containsKey("substeps") ? step["substeps"] as YamlList : YamlList(); + final newSubSteps = List.generate(subSteps.length, (j) { + final subStep = subSteps[j]; return RecipeSubStep( subStep["name"] as String, subStep["description"] as String @@ -148,15 +148,16 @@ class PizzaRecipe extends HiveObject { return Duration(seconds: recipeSteps.map((recipeStep) => recipeStep.getCurrentWaitInSeconds()).reduce((a, b) => a+b)); } + @override String toString() { - return "PizzaRecipe(${this.name}, ${this.ingredients.length}, ${this.recipeSteps.length})"; + return "PizzaRecipe($name, ${ingredients.length}, ${recipeSteps.length})"; } Table getStepTimeTable(DateTime startTime) { - List stepRows = []; + final List stepRows = []; DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(startTime.millisecondsSinceEpoch); - for (var recipeStep in this.recipeSteps.reversed) { - Duration stepWaitDuration = Duration(seconds: recipeStep.getCurrentWaitInSeconds()); + for (final recipeStep in recipeSteps.reversed) { + final Duration stepWaitDuration = Duration(seconds: recipeStep.getCurrentWaitInSeconds()); stepRows.add( TableRow( children: [ @@ -169,11 +170,11 @@ class PizzaRecipe extends HiveObject { } return Table( columnWidths: const { - 0: FlexColumnWidth(1), - 1: FlexColumnWidth(1), + 0: FlexColumnWidth(), + 1: FlexColumnWidth(), }, children: [ - TableRow( + const TableRow( children: [ TableCell(child: Center(child: Text("Step"))), TableCell(child: Center(child: Text("When"))), diff --git a/lib/entities/PizzaRecipe/recipe_step.dart b/lib/entities/PizzaRecipe/recipe_step.dart index f0979f2..6a2c62f 100644 --- a/lib/entities/PizzaRecipe/recipe_step.dart +++ b/lib/entities/PizzaRecipe/recipe_step.dart @@ -46,18 +46,20 @@ class RecipeStep extends HiveObject { RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps, {DateTime? dateTime, bool completed=false}) { waitValue = waitMin; this.dateTime = dateTime ?? DateTime.now(); - this._completed = completed; + _completed = completed; } bool _checkCompleted(){ - return subSteps.length > 0 ? + return subSteps.isNotEmpty ? subSteps.every((subStep) => subStep.completed) : - this._completed; + _completed; } void completeStepNow() { - this.subSteps.forEach((subStep) { subStep.completeNow();}); - this._completed = true; + for (final subStep in subSteps){ + subStep.completeNow(); + } + _completed = true; } int convertToSeconds(int value){ @@ -78,14 +80,14 @@ class RecipeStep extends HiveObject { } int getWaitMinInSeconds(){ - return convertToSeconds(this.waitMin); + return convertToSeconds(waitMin); } int getWaitMaxInSeconds() { - return convertToSeconds(this.waitMax); + return convertToSeconds(waitMax); } int getCurrentWaitInSeconds() { - return convertToSeconds(this.waitValue!); + return convertToSeconds(waitValue!); } } \ No newline at end of file diff --git a/lib/entities/pizza_event.dart b/lib/entities/pizza_event.dart index fa127e8..3d0f6a7 100644 --- a/lib/entities/pizza_event.dart +++ b/lib/entities/pizza_event.dart @@ -46,16 +46,16 @@ class PizzaEvent extends HiveObject{ const platformChannelSpecific = NotificationDetails(android: androidPlatformChannelSpecifics); var stepTime = tz.TZDateTime.from(dateTime, tz.local); - var durationToFirstStep = Duration(seconds: this.recipe.recipeSteps + final durationToFirstStep = Duration(seconds: recipe.recipeSteps .map((recipeStep) => recipeStep.getCurrentWaitInSeconds()) .fold(0, (a, b) => a+b)); stepTime = stepTime.subtract(durationToFirstStep); final List pendingNotificationRequests = await flutterLocalNotificationsPlugin.pendingNotificationRequests(); - int notificationId = pendingNotificationRequests.map((pendingNotification) => pendingNotification.id).fold(0, max); + final int notificationId = pendingNotificationRequests.map((pendingNotification) => pendingNotification.id).fold(0, max); int stepId = 0; - for (var recipeStep in this.recipe.recipeSteps) { + for (final recipeStep in recipe.recipeSteps) { await flutterLocalNotificationsPlugin.zonedSchedule( notificationId+stepId, recipeStep.name, @@ -63,7 +63,7 @@ class PizzaEvent extends HiveObject{ stepTime, platformChannelSpecific, androidAllowWhileIdle: true, - payload: "${this.key}__$stepId", + payload: "${key}__$stepId", uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime ); diff --git a/lib/pages/pizza_event_recipe_page.dart b/lib/pages/pizza_event_recipe_page.dart index b0b3b7d..230aa47 100644 --- a/lib/pages/pizza_event_recipe_page.dart +++ b/lib/pages/pizza_event_recipe_page.dart @@ -6,7 +6,7 @@ import 'package:url_launcher/url_launcher.dart'; class PizzaEventRecipePage extends StatefulWidget { final PizzaEvent pizzaEvent; - PizzaEventRecipePage(this.pizzaEvent); + const PizzaEventRecipePage(this.pizzaEvent); @override PizzaEventRecipePageState createState() => PizzaEventRecipePageState(); @@ -17,33 +17,33 @@ class PizzaEventRecipePageState extends State { int page = 0; PizzaEventRecipePageState(){ - this.page = controller.initialPage; + page = controller.initialPage; } @override Widget build(BuildContext context){ - var recipeStepCount = this.widget.pizzaEvent.recipe.recipeSteps.length; + var recipeStepCount = widget.pizzaEvent.recipe.recipeSteps.length; recipeStepCount += 1; // because of first description page - List pageIndex = []; + final List pageIndex = []; for (var i = 0;i < recipeStepCount;i++){ pageIndex.add( Text( "${i+1}", style: TextStyle( - color: i == this.page ? Colors.blue : Colors.grey + color: i == page ? Colors.blue : Colors.grey ) ) ); if (i != recipeStepCount-1) { pageIndex.add( - Text(" - ", style: TextStyle(color: Colors.grey)) + const Text(" - ", style: TextStyle(color: Colors.grey)) ); } } return Scaffold( appBar: AppBar( - title: Text(this.widget.pizzaEvent.recipe.name), + title: Text(widget.pizzaEvent.recipe.name), ), resizeToAvoidBottomInset: false, body: Column( @@ -51,16 +51,16 @@ class PizzaEventRecipePageState extends State { Expanded( flex: 95, child: PageView( - onPageChanged: (newPage) => setState(() {this.page = newPage;}), + onPageChanged: (newPage) => setState(() {page = newPage;}), controller: controller, children: [ Markdown( - data: this.widget.pizzaEvent.recipe.description, + data: widget.pizzaEvent.recipe.description, onTapLink: (text, url, title) { launch(url!); }, ), - ] + this.widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => buildRecipeStep(recipeStep)).toList() + ] + widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => buildRecipeStep(recipeStep)).toList() ) ), Expanded( @@ -82,7 +82,7 @@ class PizzaEventRecipePageState extends State { child: Text(recipeStep.name) ), Container( - padding: EdgeInsets.all(16), + padding: const EdgeInsets.all(16), child: MarkdownBody( data: recipeStep.description, onTapLink: (text, url, title) {