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){
return TableRow(
children: <Widget>[
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"))),
],
);
}

View file

@ -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 <int, TableColumnWidth>{
0: FlexColumnWidth(2),
1: FlexColumnWidth(1),
1: FlexColumnWidth(),
2: FlexColumnWidth(2),
},
children: <TableRow>[
TableRow(
const TableRow(
children: <TableCell>[
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<PizzaRecipe> 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<Ingredient> newIngredients = ingredients.map(
final List<Ingredient> 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<TableRow> stepRows = [];
final List<TableRow> 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: <TableCell>[
@ -169,11 +170,11 @@ class PizzaRecipe extends HiveObject {
}
return Table(
columnWidths: const <int, TableColumnWidth>{
0: FlexColumnWidth(1),
1: FlexColumnWidth(1),
0: FlexColumnWidth(),
1: FlexColumnWidth(),
},
children: <TableRow>[
TableRow(
const TableRow(
children: <TableCell>[
TableCell(child: Center(child: Text("Step"))),
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}) {
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!);
}
}

View file

@ -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<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;
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
);

View file

@ -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<PizzaEventRecipePage> {
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<Text> pageIndex = [];
final List<Text> 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<PizzaEventRecipePage> {
Expanded(
flex: 95,
child: PageView(
onPageChanged: (newPage) => setState(() {this.page = newPage;}),
onPageChanged: (newPage) => setState(() {page = newPage;}),
controller: controller,
children: <Widget>[
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<PizzaEventRecipePage> {
child: Text(recipeStep.name)
),
Container(
padding: EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
child: MarkdownBody(
data: recipeStep.description,
onTapLink: (text, url, title) {