From e950bfb74376fc703bbcfbe756ac8187c2e23979 Mon Sep 17 00:00:00 2001 From: broodjeaap89 Date: Sun, 29 Aug 2021 13:31:44 +0200 Subject: [PATCH] added method that shortens the description of the recipe for display in the recipe widget --- lib/entities/PizzaRecipe/PizzaRecipe.dart | 13 ++++++++++++- lib/widgets/PizzaRecipeWidget.dart | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/entities/PizzaRecipe/PizzaRecipe.dart b/lib/entities/PizzaRecipe/PizzaRecipe.dart index 076c056..769cea6 100644 --- a/lib/entities/PizzaRecipe/PizzaRecipe.dart +++ b/lib/entities/PizzaRecipe/PizzaRecipe.dart @@ -25,7 +25,18 @@ class PizzaRecipe extends HiveObject { List recipeSteps; PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps); - + + String getShortDescriptionString(){ + if (this.description.length < 150) { // TODO 150? + return this.description; + } + var endOfLineIndex = this.description.indexOf(RegExp("[.]|\$")) + 1; + if (endOfLineIndex >= 150){ + var first150 = this.description.substring(0, 150); + return "$first150..."; + } + return this.description.substring(0, endOfLineIndex); + } Table getIngredientsTable(int pizzaCount, int doughBallSize) { return Table( border: TableBorder.all(), diff --git a/lib/widgets/PizzaRecipeWidget.dart b/lib/widgets/PizzaRecipeWidget.dart index 69d62eb..a41ee81 100644 --- a/lib/widgets/PizzaRecipeWidget.dart +++ b/lib/widgets/PizzaRecipeWidget.dart @@ -23,7 +23,7 @@ class PizzaRecipeWidget extends StatelessWidget { Text(pizzaRecipe.name), ] ), - Text(pizzaRecipe.description), + Text(pizzaRecipe.getShortDescriptionString()), Row( mainAxisAlignment: MainAxisAlignment.center, children: [