175 lines
5.8 KiB
Dart
175 lines
5.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:table_calendar/table_calendar.dart';
|
|
|
|
class CalendarTab extends StatefulWidget {
|
|
const CalendarTab({super.key});
|
|
|
|
@override
|
|
State<CalendarTab> createState() => _CalendarTabState();
|
|
}
|
|
|
|
class _CalendarTabState extends State<CalendarTab> {
|
|
CalendarFormat _calendarFormat = CalendarFormat.month;
|
|
DateTime _focusedDay = DateTime.now();
|
|
DateTime? _selectedDay;
|
|
Map<DateTime, List<Map<String, dynamic>>> _events = {};
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
final now = DateTime.now();
|
|
_focusedDay = DateTime(now.year, now.month, now.day);
|
|
_selectedDay = _focusedDay;
|
|
|
|
// Beispiel-Events
|
|
_events = {
|
|
_focusedDay: [
|
|
{
|
|
'title': 'Ganzkörper Workout',
|
|
'time': '09:00',
|
|
'duration': '45 Minuten',
|
|
},
|
|
{'title': 'Yoga Session', 'time': '17:30', 'duration': '30 Minuten'},
|
|
],
|
|
_focusedDay.add(const Duration(days: 1)): [
|
|
{'title': 'HIIT Training', 'time': '08:00', 'duration': '30 Minuten'},
|
|
],
|
|
};
|
|
}
|
|
|
|
List<Map<String, dynamic>> _getEventsForDay(DateTime day) {
|
|
return _events[DateTime(day.year, day.month, day.day)] ?? [];
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final firstDay = DateTime.utc(2024, 1, 1);
|
|
final lastDay = DateTime.utc(2024, 12, 31);
|
|
|
|
if (_focusedDay.isBefore(firstDay)) {
|
|
_focusedDay = firstDay;
|
|
} else if (_focusedDay.isAfter(lastDay)) {
|
|
_focusedDay = lastDay;
|
|
}
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Trainingsplan'),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.add),
|
|
onPressed: () {
|
|
// TODO: Implement add workout to calendar
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: Column(
|
|
children: [
|
|
TableCalendar(
|
|
firstDay: firstDay,
|
|
lastDay: lastDay,
|
|
focusedDay: _focusedDay,
|
|
calendarFormat: _calendarFormat,
|
|
selectedDayPredicate: (day) {
|
|
return isSameDay(_selectedDay, day);
|
|
},
|
|
onDaySelected: (selectedDay, focusedDay) {
|
|
setState(() {
|
|
_selectedDay = selectedDay;
|
|
_focusedDay = focusedDay;
|
|
});
|
|
},
|
|
onFormatChanged: (format) {
|
|
setState(() {
|
|
_calendarFormat = format;
|
|
});
|
|
},
|
|
onPageChanged: (focusedDay) {
|
|
setState(() {
|
|
_focusedDay = focusedDay;
|
|
});
|
|
},
|
|
eventLoader: _getEventsForDay,
|
|
calendarStyle: const CalendarStyle(
|
|
markersMaxCount: 1,
|
|
markerDecoration: BoxDecoration(
|
|
color: Colors.blue,
|
|
shape: BoxShape.circle,
|
|
),
|
|
),
|
|
),
|
|
const Divider(),
|
|
Expanded(
|
|
child:
|
|
_getEventsForDay(_selectedDay!).isEmpty
|
|
? const Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.event_busy, size: 64, color: Colors.grey),
|
|
SizedBox(height: 16),
|
|
Text(
|
|
'Keine Trainings geplant',
|
|
style: TextStyle(fontSize: 18, color: Colors.grey),
|
|
),
|
|
SizedBox(height: 8),
|
|
Text(
|
|
'Füge Trainings zu deinem Kalender hinzu',
|
|
style: TextStyle(fontSize: 14, color: Colors.grey),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: ListView.builder(
|
|
padding: const EdgeInsets.all(16),
|
|
itemCount: _getEventsForDay(_selectedDay!).length,
|
|
itemBuilder: (context, index) {
|
|
final event = _getEventsForDay(_selectedDay!)[index];
|
|
return Card(
|
|
margin: const EdgeInsets.only(bottom: 16),
|
|
child: ListTile(
|
|
leading: Container(
|
|
width: 48,
|
|
height: 48,
|
|
decoration: BoxDecoration(
|
|
color: Colors.blue[100],
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: const Icon(
|
|
Icons.fitness_center,
|
|
color: Colors.blue,
|
|
),
|
|
),
|
|
title: Text(
|
|
event['title'],
|
|
style: const TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
subtitle: Text(
|
|
'${event['time']} • ${event['duration']}',
|
|
),
|
|
trailing: IconButton(
|
|
icon: const Icon(Icons.delete_outline),
|
|
onPressed: () {
|
|
// TODO: Implement delete workout from calendar
|
|
},
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () {
|
|
// TODO: Implement add workout to calendar
|
|
},
|
|
child: const Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
}
|