Time
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:todoapp/elems/todo.dart';
|
||||
import 'package:todoapp/modals/datepickermodal.dart';
|
||||
import 'package:todoapp/modals/timepickermodal.dart';
|
||||
import 'package:todoapp/providers/todoprovider.dart';
|
||||
|
||||
@@ -4,24 +4,116 @@ import 'package:todoapp/modals/edittodomodal.dart';
|
||||
import 'package:todoapp/providers/todoprovider.dart';
|
||||
|
||||
class TodoWidget extends StatefulWidget {
|
||||
const TodoWidget({super.key, required this.checked, required this.title});
|
||||
const TodoWidget(
|
||||
{super.key,
|
||||
required this.checked,
|
||||
required this.title,
|
||||
required this.dueTime});
|
||||
|
||||
final bool checked;
|
||||
final String title;
|
||||
final DateTime dueTime;
|
||||
|
||||
@override
|
||||
State<TodoWidget> createState() => _TodoWidgetState();
|
||||
}
|
||||
|
||||
class _TodoWidgetState extends State<TodoWidget> {
|
||||
String formatNumber(int number) {
|
||||
if (number < 10) {
|
||||
return "0$number";
|
||||
}
|
||||
return number.toString();
|
||||
}
|
||||
|
||||
List<dynamic> buildDisplayString() {
|
||||
DateTime today = DateTime.now();
|
||||
DateTime due = widget.dueTime;
|
||||
|
||||
DateTime nowDay = DateTime(2000, 1, today.day);
|
||||
DateTime dueDay = DateTime(2000, 1, due.day);
|
||||
int diff = dueDay.difference(nowDay).inDays;
|
||||
|
||||
Map<int, String> monthList = {
|
||||
1: "Jan",
|
||||
2: "Feb",
|
||||
3: "Mar",
|
||||
4: "Apr",
|
||||
5: "Mai",
|
||||
6: "Jun",
|
||||
7: "Jul",
|
||||
8: "Aug",
|
||||
9: "Sep",
|
||||
10: "Okt",
|
||||
11: "Nov",
|
||||
12: "Dez"
|
||||
};
|
||||
|
||||
if (diff < 0) {
|
||||
return [
|
||||
"Over",
|
||||
Colors.red,
|
||||
Colors.white
|
||||
];
|
||||
}
|
||||
else if (diff < 1) {
|
||||
return [
|
||||
"Today ${formatNumber(due.hour)}:${formatNumber(due.minute)}",
|
||||
Theme.of(context).colorScheme.primary,
|
||||
Colors.black
|
||||
];
|
||||
} else if (diff < 2) {
|
||||
return [
|
||||
"Tomorrow ${formatNumber(due.hour)}:${formatNumber(due.minute)}",
|
||||
Theme.of(context).colorScheme.inversePrimary,
|
||||
Colors.white
|
||||
];
|
||||
} else if (diff < 7) {
|
||||
return [
|
||||
"In $diff days",
|
||||
Theme.of(context).colorScheme.secondary.withOpacity(0.35),
|
||||
Colors.white
|
||||
];
|
||||
}
|
||||
else {
|
||||
return [
|
||||
"${monthList[due.month]} ${formatNumber(due.day)}, ${due.year}",
|
||||
Theme.of(context).colorScheme.secondary.withOpacity(0.35),
|
||||
Colors.white
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onLongPress: () {
|
||||
EditTodoModal.add(context, widget.title);
|
||||
EditTodoModal.add(context, widget.title, widget.dueTime);
|
||||
},
|
||||
child: CheckboxListTile(
|
||||
value: widget.checked,
|
||||
subtitle: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding:
|
||||
widget.checked ? EdgeInsets.zero : const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: widget.checked
|
||||
? const Color(0x00000000)
|
||||
: buildDisplayString()[1],
|
||||
borderRadius: BorderRadius.circular(10)),
|
||||
child: Text(
|
||||
buildDisplayString()[0],
|
||||
style: TextStyle(
|
||||
color:
|
||||
widget.checked ? Colors.white : buildDisplayString()[2],
|
||||
decoration: widget.checked
|
||||
? TextDecoration.lineThrough
|
||||
: TextDecoration.none),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
title: Text(widget.title,
|
||||
style: widget.checked
|
||||
? const TextStyle(decoration: TextDecoration.lineThrough)
|
||||
|
||||
Reference in New Issue
Block a user