update scheduler

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Sven laptop
2026-05-06 18:09:12 +02:00
parent 68490f8fd5
commit d81da9a475
9 changed files with 1430 additions and 56 deletions
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import '../models/schedule.dart';
import '../services/schedule_service.dart';
import '../services/auth_service.dart';
import '../services/exceptions.dart';
import '../widgets/route_card.dart';
class DailyScheduleScreen extends StatefulWidget {
@@ -12,6 +14,7 @@ class DailyScheduleScreen extends StatefulWidget {
class _DailyScheduleScreenState extends State<DailyScheduleScreen> {
final _scheduleService = ScheduleService();
final _authService = AuthService();
late Future<DailySchedule> _scheduleFuture;
DateTime _selectedDate = DateTime.now();
@@ -21,6 +24,13 @@ class _DailyScheduleScreenState extends State<DailyScheduleScreen> {
_scheduleFuture = _scheduleService.getTodaySchedule();
}
Future<void> _handleLogout() async {
await _authService.logout();
if (mounted) {
Navigator.of(context).pushReplacementNamed('/login');
}
}
Future<void> _refreshSchedule() async {
setState(() {
_scheduleFuture = _scheduleService.getDailySchedule(_selectedDate);
@@ -65,6 +75,13 @@ class _DailyScheduleScreenState extends State<DailyScheduleScreen> {
appBar: AppBar(
title: const Text('Today on the Road'),
elevation: 0,
actions: [
IconButton(
icon: const Icon(Icons.logout),
tooltip: 'Logout',
onPressed: _handleLogout,
),
],
),
body: Container(
decoration: BoxDecoration(
@@ -149,6 +166,13 @@ class _DailyScheduleScreenState extends State<DailyScheduleScreen> {
}
if (snapshot.hasError) {
// Auto-logout on session expiry
if (snapshot.error is UnauthorizedException) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_handleLogout();
});
}
return Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
@@ -162,21 +186,27 @@ class _DailyScheduleScreenState extends State<DailyScheduleScreen> {
),
const SizedBox(height: 16),
Text(
'Failed to load schedule',
snapshot.error is UnauthorizedException
? 'Session Expired'
: 'Failed to load schedule',
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 8),
Text(
snapshot.error.toString(),
snapshot.error is UnauthorizedException
? 'Redirecting to login...'
: snapshot.error.toString(),
style: Theme.of(context).textTheme.bodySmall,
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
FilledButton.icon(
onPressed: _refreshSchedule,
icon: const Icon(Icons.refresh),
label: const Text('Retry'),
),
if (snapshot.error is! UnauthorizedException) ...[
const SizedBox(height: 24),
FilledButton.icon(
onPressed: _refreshSchedule,
icon: const Icon(Icons.refresh),
label: const Text('Retry'),
),
],
],
),
),