GardenPlanner/lib/logic/plant.service.dart

43 lines
1.1 KiB
Dart
Raw Permalink Normal View History

2023-06-25 10:13:39 +02:00
import 'package:flutter/material.dart';
2023-06-25 10:15:30 +02:00
import '../constance.dart';
2023-06-25 10:13:39 +02:00
import '../entities/plant.dart';
import '../entities/plant_time.dart';
import 'date.helper.dart';
class PlantService {
String getTimeDescription(final Plant plant, final DateTime date) {
var plantTimes = _getPlantTimes(plant, date);
if (plantTimes.isNotEmpty) {
return plantTimes.first.description;
}
return Constance.defaultDescription;
}
Color getColor(final Plant plant, final DateTime date) {
Color color = Constance.defaultColor;
if (plant.times.isNotEmpty) {
for (var time in plant.times) {
if (DateHelper.isDateBetween(date, time.from, time.until)) {
color = time.color;
break;
}
}
}
return color;
}
bool isActionNeeded(final Plant plant, final DateTime date) {
return _getPlantTimes(plant, date).any((time) => time.action);
}
List<PlantTime> _getPlantTimes(final Plant plant, final DateTime date) {
return plant.times
.where((time) => DateHelper.isDateBetween(date, time.from, time.until))
.toList();
}
}