todotxt_reminder/lib/repeating_task.dart

46 lines
1.4 KiB
Dart
Raw Permalink Normal View History

2023-01-07 21:23:59 +00:00
import 'package:flutter/material.dart';
import 'package:nextcloud_reminder/task_item.dart';
import 'package:nextcloud_reminder/types/tasks.dart';
2023-01-07 21:23:59 +00:00
class RepeatingTask extends StatefulWidget {
2023-01-10 22:55:38 +00:00
const RepeatingTask({super.key, required this.task});
2023-01-07 21:23:59 +00:00
2023-01-10 22:55:38 +00:00
final TaskExtra task;
2023-01-07 21:23:59 +00:00
@override
State<StatefulWidget> createState() => _RepeatingTaskState();
}
class _RepeatingTaskState extends State<RepeatingTask> {
late List<TaskItem> _occurrences;
@override
void initState() {
super.initState();
2023-01-10 22:55:38 +00:00
_occurrences = List<TaskItem>.generate(10, (index) {
var start = widget.task.begin ?? DateTime.now();
var comparator = DateTime.now().add(Duration(days: index));
for (var r in widget.task.repeat) {
if (r.repeatHit(start, comparator)) return TaskItem(done: widget.task.done,);
}
if (widget.task.repeat.isEmpty && start.day == comparator.day && start.month == comparator.month && start.year == comparator.year) {
return TaskItem(done: widget.task.done,);
}
return const TaskItem(done: null);
});
2023-01-07 21:23:59 +00:00
}
@override
Widget build(BuildContext context) {
return Container(
2023-01-13 21:39:05 +00:00
decoration: BoxDecoration(border: Border(
bottom: BorderSide(color: Theme.of(context).colorScheme.background, width: 1),
),),
margin: const EdgeInsets.all(0.0),
child: Row(
2023-01-07 21:23:59 +00:00
crossAxisAlignment: CrossAxisAlignment.start,
children: _occurrences,
)
);
2023-01-07 21:23:59 +00:00
}
}