fixed all the linting errors in the entities

This commit is contained in:
broodjeaap89 2021-09-03 17:33:38 +02:00
parent eacfd10580
commit 26d18d7818
5 changed files with 60 additions and 57 deletions

View file

@ -24,9 +24,9 @@ class Ingredient extends HiveObject {
TableRow getIngredientTableRow(int pizzaCount, int doughBallSize){ TableRow getIngredientTableRow(int pizzaCount, int doughBallSize){
return TableRow( return TableRow(
children: <Widget>[ children: <Widget>[
TableCell(child: Center(child: Text("${this.name.capitalize()}"))), TableCell(child: Center(child: Text(name.capitalize()))),
TableCell(child: Center(child: Text("${this.getAbsoluteString(doughBallSize)}$unit"))), TableCell(child: Center(child: Text("${getAbsoluteString(doughBallSize)}$unit"))),
TableCell(child: Center(child: Text("${this.getAbsoluteString(pizzaCount * doughBallSize)}$unit"))), TableCell(child: Center(child: Text("${getAbsoluteString(pizzaCount * doughBallSize)}$unit"))),
], ],
); );
} }

View file

@ -27,26 +27,26 @@ class PizzaRecipe extends HiveObject {
PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps); PizzaRecipe(this.name, this.description, this.ingredients, this.recipeSteps);
String getShortDescriptionString(){ String getShortDescriptionString(){
if (this.description.length < 150) { // TODO 150? if (description.length < 150) { // TODO 150?
return this.description; return description;
} }
var endOfLineIndex = this.description.indexOf(RegExp("[.]|\$")) + 1; final endOfLineIndex = description.indexOf(RegExp("[.]|\$")) + 1;
if (endOfLineIndex >= 150){ if (endOfLineIndex >= 150){
var first150 = this.description.substring(0, 150); final first150 = description.substring(0, 150);
return "$first150..."; return "$first150...";
} }
return this.description.substring(0, endOfLineIndex); return description.substring(0, endOfLineIndex);
} }
Table getIngredientsTable(int pizzaCount, int doughBallSize) { Table getIngredientsTable(int pizzaCount, int doughBallSize) {
return Table( return Table(
border: TableBorder.all(), border: TableBorder.all(),
columnWidths: const <int, TableColumnWidth>{ columnWidths: const <int, TableColumnWidth>{
0: FlexColumnWidth(2), 0: FlexColumnWidth(2),
1: FlexColumnWidth(1), 1: FlexColumnWidth(),
2: FlexColumnWidth(2), 2: FlexColumnWidth(2),
}, },
children: <TableRow>[ children: <TableRow>[
TableRow( const TableRow(
children: <TableCell>[ children: <TableCell>[
TableCell(child: Center(child: Text("Ingredient"))), TableCell(child: Center(child: Text("Ingredient"))),
TableCell(child: Center(child: Text("Per Ball"))), TableCell(child: Center(child: Text("Per Ball"))),
@ -63,7 +63,7 @@ class PizzaRecipe extends HiveObject {
int getStepsCompleted(){ int getStepsCompleted(){
var stepCount = 0; var stepCount = 0;
for (var recipeStep in this.recipeSteps) { for (final recipeStep in recipeSteps) {
if (!recipeStep.completed) { if (!recipeStep.completed) {
return stepCount; return stepCount;
} }
@ -73,27 +73,27 @@ class PizzaRecipe extends HiveObject {
} }
static Future<PizzaRecipe> fromYaml(String yamlPath) async{ static Future<PizzaRecipe> fromYaml(String yamlPath) async{
String yamlString = await loadAsset(yamlPath); final String yamlString = await loadAsset(yamlPath);
var yaml = loadYaml(yamlString); final yaml = loadYaml(yamlString);
YamlMap recipe = yaml["recipe"] as YamlMap; final YamlMap recipe = yaml["recipe"] as YamlMap;
String name = recipe["name"] as String; final String name = recipe["name"] as String;
String description = recipe["description"] as String; final String description = recipe["description"] as String;
YamlList ingredients = recipe["ingredients"] as YamlList; final YamlList ingredients = recipe["ingredients"] as YamlList;
List<Ingredient> newIngredients = ingredients.map( final List<Ingredient> newIngredients = ingredients.map(
(ingredient) => Ingredient( (ingredient) => Ingredient(
ingredient["name"] as String, ingredient["name"] as String,
ingredient["unit"] as String, ingredient["unit"] as String,
ingredient["value"] as double ingredient["value"] as double
)).toList(); )).toList();
YamlList steps = recipe["steps"] as YamlList; final YamlList steps = recipe["steps"] as YamlList;
var newRecipeSteps = List.generate(steps.length, (i) { final newRecipeSteps = List.generate(steps.length, (i) {
YamlMap step = steps[i] as YamlMap; final YamlMap step = steps[i] as YamlMap;
String stepName = step["name"] as String; final String stepName = step["name"] as String;
String stepDescription = step["description"] as String; final String stepDescription = step["description"] as String;
String waitUnit = "none"; String waitUnit = "none";
String waitDescription = ""; String waitDescription = "";
@ -101,7 +101,7 @@ class PizzaRecipe extends HiveObject {
int waitMax = 0; int waitMax = 0;
if (step.containsKey("wait")) { if (step.containsKey("wait")) {
YamlMap waitMap = step["wait"] as YamlMap; final YamlMap waitMap = step["wait"] as YamlMap;
waitDescription = waitMap["description"] as String; waitDescription = waitMap["description"] as String;
waitUnit = waitMap["unit"] as String; waitUnit = waitMap["unit"] as String;
@ -109,9 +109,9 @@ class PizzaRecipe extends HiveObject {
waitMax = waitMap["max"] as int; waitMax = waitMap["max"] as int;
} }
YamlList subSteps = step.containsKey("substeps") ? step["substeps"] as YamlList : YamlList(); final YamlList subSteps = step.containsKey("substeps") ? step["substeps"] as YamlList : YamlList();
var newSubSteps = List.generate(subSteps.length, (j) { final newSubSteps = List.generate(subSteps.length, (j) {
var subStep = subSteps[j]; final subStep = subSteps[j];
return RecipeSubStep( return RecipeSubStep(
subStep["name"] as String, subStep["name"] as String,
subStep["description"] 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)); return Duration(seconds: recipeSteps.map((recipeStep) => recipeStep.getCurrentWaitInSeconds()).reduce((a, b) => a+b));
} }
@override
String toString() { String toString() {
return "PizzaRecipe(${this.name}, ${this.ingredients.length}, ${this.recipeSteps.length})"; return "PizzaRecipe($name, ${ingredients.length}, ${recipeSteps.length})";
} }
Table getStepTimeTable(DateTime startTime) { Table getStepTimeTable(DateTime startTime) {
List<TableRow> stepRows = []; final List<TableRow> stepRows = [];
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(startTime.millisecondsSinceEpoch); DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(startTime.millisecondsSinceEpoch);
for (var recipeStep in this.recipeSteps.reversed) { for (final recipeStep in recipeSteps.reversed) {
Duration stepWaitDuration = Duration(seconds: recipeStep.getCurrentWaitInSeconds()); final Duration stepWaitDuration = Duration(seconds: recipeStep.getCurrentWaitInSeconds());
stepRows.add( stepRows.add(
TableRow( TableRow(
children: <TableCell>[ children: <TableCell>[
@ -169,11 +170,11 @@ class PizzaRecipe extends HiveObject {
} }
return Table( return Table(
columnWidths: const <int, TableColumnWidth>{ columnWidths: const <int, TableColumnWidth>{
0: FlexColumnWidth(1), 0: FlexColumnWidth(),
1: FlexColumnWidth(1), 1: FlexColumnWidth(),
}, },
children: <TableRow>[ children: <TableRow>[
TableRow( const TableRow(
children: <TableCell>[ children: <TableCell>[
TableCell(child: Center(child: Text("Step"))), TableCell(child: Center(child: Text("Step"))),
TableCell(child: Center(child: Text("When"))), TableCell(child: Center(child: Text("When"))),

View file

@ -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}) { RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps, {DateTime? dateTime, bool completed=false}) {
waitValue = waitMin; waitValue = waitMin;
this.dateTime = dateTime ?? DateTime.now(); this.dateTime = dateTime ?? DateTime.now();
this._completed = completed; _completed = completed;
} }
bool _checkCompleted(){ bool _checkCompleted(){
return subSteps.length > 0 ? return subSteps.isNotEmpty ?
subSteps.every((subStep) => subStep.completed) : subSteps.every((subStep) => subStep.completed) :
this._completed; _completed;
} }
void completeStepNow() { void completeStepNow() {
this.subSteps.forEach((subStep) { subStep.completeNow();}); for (final subStep in subSteps){
this._completed = true; subStep.completeNow();
}
_completed = true;
} }
int convertToSeconds(int value){ int convertToSeconds(int value){
@ -78,14 +80,14 @@ class RecipeStep extends HiveObject {
} }
int getWaitMinInSeconds(){ int getWaitMinInSeconds(){
return convertToSeconds(this.waitMin); return convertToSeconds(waitMin);
} }
int getWaitMaxInSeconds() { int getWaitMaxInSeconds() {
return convertToSeconds(this.waitMax); return convertToSeconds(waitMax);
} }
int getCurrentWaitInSeconds() { int getCurrentWaitInSeconds() {
return convertToSeconds(this.waitValue!); return convertToSeconds(waitValue!);
} }
} }

View file

@ -46,16 +46,16 @@ class PizzaEvent extends HiveObject{
const platformChannelSpecific = NotificationDetails(android: androidPlatformChannelSpecifics); const platformChannelSpecific = NotificationDetails(android: androidPlatformChannelSpecifics);
var stepTime = tz.TZDateTime.from(dateTime, tz.local); 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()) .map((recipeStep) => recipeStep.getCurrentWaitInSeconds())
.fold(0, (a, b) => a+b)); .fold(0, (a, b) => a+b));
stepTime = stepTime.subtract(durationToFirstStep); stepTime = stepTime.subtract(durationToFirstStep);
final List<PendingNotificationRequest> pendingNotificationRequests = await flutterLocalNotificationsPlugin.pendingNotificationRequests(); final List<PendingNotificationRequest> 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; int stepId = 0;
for (var recipeStep in this.recipe.recipeSteps) { for (final recipeStep in recipe.recipeSteps) {
await flutterLocalNotificationsPlugin.zonedSchedule( await flutterLocalNotificationsPlugin.zonedSchedule(
notificationId+stepId, notificationId+stepId,
recipeStep.name, recipeStep.name,
@ -63,7 +63,7 @@ class PizzaEvent extends HiveObject{
stepTime, stepTime,
platformChannelSpecific, platformChannelSpecific,
androidAllowWhileIdle: true, androidAllowWhileIdle: true,
payload: "${this.key}__$stepId", payload: "${key}__$stepId",
uiLocalNotificationDateInterpretation: uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime UILocalNotificationDateInterpretation.absoluteTime
); );

View file

@ -6,7 +6,7 @@ import 'package:url_launcher/url_launcher.dart';
class PizzaEventRecipePage extends StatefulWidget { class PizzaEventRecipePage extends StatefulWidget {
final PizzaEvent pizzaEvent; final PizzaEvent pizzaEvent;
PizzaEventRecipePage(this.pizzaEvent); const PizzaEventRecipePage(this.pizzaEvent);
@override @override
PizzaEventRecipePageState createState() => PizzaEventRecipePageState(); PizzaEventRecipePageState createState() => PizzaEventRecipePageState();
@ -17,33 +17,33 @@ class PizzaEventRecipePageState extends State<PizzaEventRecipePage> {
int page = 0; int page = 0;
PizzaEventRecipePageState(){ PizzaEventRecipePageState(){
this.page = controller.initialPage; page = controller.initialPage;
} }
@override @override
Widget build(BuildContext context){ 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 recipeStepCount += 1; // because of first description page
List<Text> pageIndex = []; final List<Text> pageIndex = [];
for (var i = 0;i < recipeStepCount;i++){ for (var i = 0;i < recipeStepCount;i++){
pageIndex.add( pageIndex.add(
Text( Text(
"${i+1}", "${i+1}",
style: TextStyle( style: TextStyle(
color: i == this.page ? Colors.blue : Colors.grey color: i == page ? Colors.blue : Colors.grey
) )
) )
); );
if (i != recipeStepCount-1) { if (i != recipeStepCount-1) {
pageIndex.add( pageIndex.add(
Text(" - ", style: TextStyle(color: Colors.grey)) const Text(" - ", style: TextStyle(color: Colors.grey))
); );
} }
} }
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(this.widget.pizzaEvent.recipe.name), title: Text(widget.pizzaEvent.recipe.name),
), ),
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
body: Column( body: Column(
@ -51,16 +51,16 @@ class PizzaEventRecipePageState extends State<PizzaEventRecipePage> {
Expanded( Expanded(
flex: 95, flex: 95,
child: PageView( child: PageView(
onPageChanged: (newPage) => setState(() {this.page = newPage;}), onPageChanged: (newPage) => setState(() {page = newPage;}),
controller: controller, controller: controller,
children: <Widget>[ children: <Widget>[
Markdown( Markdown(
data: this.widget.pizzaEvent.recipe.description, data: widget.pizzaEvent.recipe.description,
onTapLink: (text, url, title) { onTapLink: (text, url, title) {
launch(url!); launch(url!);
}, },
), ),
] + this.widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => buildRecipeStep(recipeStep)).toList() ] + widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => buildRecipeStep(recipeStep)).toList()
) )
), ),
Expanded( Expanded(
@ -82,7 +82,7 @@ class PizzaEventRecipePageState extends State<PizzaEventRecipePage> {
child: Text(recipeStep.name) child: Text(recipeStep.name)
), ),
Container( Container(
padding: EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: MarkdownBody( child: MarkdownBody(
data: recipeStep.description, data: recipeStep.description,
onTapLink: (text, url, title) { onTapLink: (text, url, title) {