From 7dde66b89c644847dd8a4bcece1fc482f1b4c76e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20M=C3=BCller?= Date: Mon, 19 Jun 2023 18:10:42 +0200 Subject: [PATCH] Limit timetable scrolling so no errors occur --- lib/model/timetable/timetableProps.dart | 13 +++++++++++++ lib/view/pages/timetable/timetable.dart | 9 +++++++++ lib/widget/placeholderView.dart | 5 ++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/model/timetable/timetableProps.dart b/lib/model/timetable/timetableProps.dart index 71f15d9..3772446 100644 --- a/lib/model/timetable/timetableProps.dart +++ b/lib/model/timetable/timetableProps.dart @@ -105,4 +105,17 @@ class TimetableProps extends DataHolder { notifyListeners(); } } + + void resetWeek() { + error = null; + notifyListeners(); + + DateTime queryWeek = DateTime.now().add(const Duration(days: 2)); + + startDate = getDate(queryWeek.subtract(Duration(days: queryWeek.weekday - 1))); + endDate = getDate(queryWeek.add(Duration(days: DateTime.daysPerWeek - queryWeek.weekday))); + + run(); + notifyListeners(); + } } \ No newline at end of file diff --git a/lib/view/pages/timetable/timetable.dart b/lib/view/pages/timetable/timetable.dart index cbe4166..86aaf51 100644 --- a/lib/view/pages/timetable/timetable.dart +++ b/lib/view/pages/timetable/timetable.dart @@ -72,6 +72,12 @@ class _TimetableState extends State { return PlaceholderView( icon: Icons.calendar_month, text: "Webuntis error: ${value.error.toString()}", + button: TextButton( + child: const Text("Neu laden"), + onPressed: () { + Provider.of(context, listen: false).resetWeek(); + }, + ), ); } @@ -90,6 +96,9 @@ class _TimetableState extends State { view: CalendarView.workWeek, dataSource: _buildTableEvents(value), + maxDate: DateTime.now().add(const Duration(days: 7)), + minDate: DateTime.now().subtract(const Duration (days: 14)), + controller: controller, onViewChanged: (ViewChangedDetails details) { diff --git a/lib/widget/placeholderView.dart b/lib/widget/placeholderView.dart index f2f198e..9dda920 100644 --- a/lib/widget/placeholderView.dart +++ b/lib/widget/placeholderView.dart @@ -3,7 +3,8 @@ import 'package:flutter/material.dart'; class PlaceholderView extends StatelessWidget { final IconData icon; final String text; - const PlaceholderView({Key? key, required this.icon, required this.text}) : super(key: key); + final Widget? button; + const PlaceholderView({Key? key, required this.icon, required this.text, this.button}) : super(key: key); @override Widget build(BuildContext context) { @@ -25,6 +26,8 @@ class PlaceholderView extends StatelessWidget { ), textAlign: TextAlign.center, ), + const SizedBox(height: 30), + if(button != null) button!, ], ), ),