9d1a37e248
Build and Push Docker Images / detect-changes (push) Successful in 10s
Build and Push Docker Images / build-auth-api (push) Successful in 58s
Build and Push Docker Images / build-employee-api (push) Successful in 58s
Build and Push Docker Images / build-transit-api (push) Successful in 59s
Build and Push Docker Images / build-error-log-api (push) Successful in 1m8s
Build and Push Docker Images / build-admin-ui (push) Successful in 1m14s
Build and Push Docker Images / deploy-test-node (push) Successful in 5s
372 lines
15 KiB
Dart
372 lines
15 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../models/schedule.dart' as schedule;
|
|
import '../services/schedule_service.dart';
|
|
import '../services/auth_service.dart';
|
|
import '../services/exceptions.dart';
|
|
import '../widgets/route_card.dart';
|
|
|
|
class DailyScheduleScreen extends StatefulWidget {
|
|
const DailyScheduleScreen({super.key});
|
|
|
|
@override
|
|
State<DailyScheduleScreen> createState() => _DailyScheduleScreenState();
|
|
}
|
|
|
|
class _DailyScheduleScreenState extends State<DailyScheduleScreen> {
|
|
final _scheduleService = ScheduleService();
|
|
final _authService = AuthService();
|
|
late Future<schedule.DailySchedule> _scheduleFuture;
|
|
DateTime _selectedDate = DateTime.now();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_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);
|
|
});
|
|
}
|
|
|
|
Future<void> _selectDate() async {
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
final picked = await showDatePicker(
|
|
context: context,
|
|
initialDate: _selectedDate,
|
|
firstDate: DateTime.now().subtract(const Duration(days: 7)),
|
|
lastDate: DateTime.now().add(const Duration(days: 30)),
|
|
builder: (context, child) {
|
|
return Theme(
|
|
data: Theme.of(context).copyWith(
|
|
dialogBackgroundColor: colorScheme.surface,
|
|
),
|
|
child: child!,
|
|
);
|
|
},
|
|
);
|
|
|
|
if (picked != null && picked != _selectedDate) {
|
|
setState(() {
|
|
_selectedDate = picked;
|
|
});
|
|
_refreshSchedule();
|
|
}
|
|
}
|
|
|
|
// Group routes by hour for better visual organization
|
|
Map<int, List<schedule.Route>> _groupByHour(List<schedule.Route> routes) {
|
|
final grouped = <int, List<schedule.Route>>{};
|
|
for (final route in routes) {
|
|
final hour = route.startTime.hour;
|
|
grouped.putIfAbsent(hour, () => []).add(route);
|
|
}
|
|
return grouped;
|
|
}
|
|
|
|
void _moveDay(int deltaDays) {
|
|
setState(() {
|
|
_selectedDate = _selectedDate.add(Duration(days: deltaDays));
|
|
_scheduleFuture = _scheduleService.getDailySchedule(_selectedDate);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
final dateStr =
|
|
'${_selectedDate.year}-${_selectedDate.month.toString().padLeft(2, '0')}-${_selectedDate.day.toString().padLeft(2, '0')}';
|
|
final today = DateTime.now();
|
|
final isToday = DateTime(_selectedDate.year, _selectedDate.month, _selectedDate.day) ==
|
|
DateTime(today.year, today.month, today.day);
|
|
|
|
return Scaffold(
|
|
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(
|
|
gradient: LinearGradient(
|
|
colors: Theme.of(context).brightness == Brightness.dark
|
|
? const [Color(0xFF0B1220), Color(0xFF111827)]
|
|
: const [Color(0xFFF1F5F9), Color(0xFFE2E8F0)],
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
margin: const EdgeInsets.fromLTRB(16, 16, 16, 12),
|
|
padding: const EdgeInsets.all(18),
|
|
decoration: BoxDecoration(
|
|
gradient: const LinearGradient(
|
|
colors: [Color(0xFF0F172A), Color(0xFF1D4ED8)],
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
),
|
|
borderRadius: BorderRadius.circular(24),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.16),
|
|
blurRadius: 22,
|
|
offset: const Offset(0, 10),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
isToday ? 'Vandaag' : 'Geplande datum',
|
|
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
|
color: Colors.white.withOpacity(0.78),
|
|
),
|
|
),
|
|
const SizedBox(height: 6),
|
|
Text(
|
|
dateStr,
|
|
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w800,
|
|
),
|
|
),
|
|
const SizedBox(height: 6),
|
|
Text(
|
|
'Routes, stops en status in één overzicht',
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
color: Colors.white.withOpacity(0.84),
|
|
),
|
|
),
|
|
const SizedBox(height: 14),
|
|
Align(
|
|
alignment: Alignment.centerRight,
|
|
child: Wrap(
|
|
spacing: 8,
|
|
runSpacing: 8,
|
|
alignment: WrapAlignment.end,
|
|
children: [
|
|
SizedBox(
|
|
height: 48,
|
|
child: OutlinedButton.icon(
|
|
onPressed: () => _moveDay(-1),
|
|
icon: const Icon(Icons.chevron_left, size: 18),
|
|
label: const Text('Vorige dag'),
|
|
style: OutlinedButton.styleFrom(
|
|
foregroundColor: Colors.white,
|
|
side: BorderSide(color: Colors.white.withOpacity(0.28)),
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 48,
|
|
child: OutlinedButton.icon(
|
|
onPressed: _selectDate,
|
|
icon: const Icon(Icons.calendar_today, size: 18),
|
|
label: const Text('Kies datum'),
|
|
style: OutlinedButton.styleFrom(
|
|
foregroundColor: Colors.white,
|
|
side: BorderSide(color: Colors.white.withOpacity(0.28)),
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 48,
|
|
child: OutlinedButton.icon(
|
|
onPressed: () => _moveDay(1),
|
|
icon: const Icon(Icons.chevron_right, size: 18),
|
|
label: const Text('Volgende dag'),
|
|
style: OutlinedButton.styleFrom(
|
|
foregroundColor: Colors.white,
|
|
side: BorderSide(color: Colors.white.withOpacity(0.28)),
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: FutureBuilder<schedule.DailySchedule>(
|
|
future: _scheduleFuture,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
|
|
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),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
Icons.error_outline,
|
|
size: 64,
|
|
color: colorScheme.error,
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
snapshot.error is UnauthorizedException
|
|
? 'Session Expired'
|
|
: 'Failed to load schedule',
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
snapshot.error is UnauthorizedException
|
|
? 'Redirecting to login...'
|
|
: snapshot.error.toString(),
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
if (snapshot.error is! UnauthorizedException) ...[
|
|
const SizedBox(height: 24),
|
|
FilledButton.icon(
|
|
onPressed: _refreshSchedule,
|
|
icon: const Icon(Icons.refresh),
|
|
label: const Text('Retry'),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (!snapshot.hasData || snapshot.data!.routes.isEmpty) {
|
|
return Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
Icons.calendar_today,
|
|
size: 64,
|
|
color: colorScheme.outline,
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
'Geen actieve ritten',
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
'Je hebt geen geplande ritten voor deze dag',
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: colorScheme.onSurfaceVariant,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
final routes = [...snapshot.data!.routes]
|
|
..sort((a, b) => a.startTime.compareTo(b.startTime));
|
|
final scheduledRoutes = routes.where((r) => r.status == 'scheduled').toList();
|
|
final inProgressRoutes = routes.where((r) => r.status == 'in_progress').toList();
|
|
|
|
// Merge and group by hour
|
|
final allActiveRoutes = [...inProgressRoutes, ...scheduledRoutes]
|
|
..sort((a, b) => a.startTime.compareTo(b.startTime));
|
|
final hourGroups = _groupByHour(allActiveRoutes);
|
|
final sortedHours = hourGroups.keys.toList()..sort();
|
|
|
|
return RefreshIndicator(
|
|
onRefresh: _refreshSchedule,
|
|
child: ListView(
|
|
padding: const EdgeInsets.only(bottom: 16),
|
|
children: [
|
|
if (allActiveRoutes.isEmpty)
|
|
Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 32),
|
|
child: Text(
|
|
'Geen actieve ritten voor deze dag',
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
color: colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
),
|
|
)
|
|
else
|
|
...sortedHours.map((hour) {
|
|
final routesForHour = hourGroups[hour] ?? [];
|
|
return Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 16, top: 16, bottom: 8),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
'${hour.toString().padLeft(2, '0')}:00 uur',
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
fontWeight: FontWeight.bold,
|
|
color: colorScheme.primary,
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Container(
|
|
height: 1,
|
|
color: colorScheme.outlineVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
...routesForHour.map((route) => Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
child: RouteCard(route: route, onTap: () {}),
|
|
)),
|
|
const SizedBox(height: 4),
|
|
],
|
|
);
|
|
}),
|
|
const SizedBox(height: 8),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|