120 lines
3.9 KiB
Dart
120 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_bloc.dart';
|
|
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_event.dart';
|
|
import 'package:hl_lieferservice/feature/delivery/overview/presentation/delivery_info.dart';
|
|
import 'package:hl_lieferservice/feature/delivery/overview/presentation/delivery_list.dart';
|
|
import 'package:hl_lieferservice/model/tour.dart';
|
|
|
|
import '../../../authentication/bloc/auth_bloc.dart';
|
|
import '../../../authentication/bloc/auth_state.dart';
|
|
|
|
class DeliveryOverview extends StatefulWidget {
|
|
const DeliveryOverview({super.key, required this.tour});
|
|
|
|
final Tour tour;
|
|
|
|
@override
|
|
State<StatefulWidget> createState() => _DeliveryOverviewState();
|
|
}
|
|
|
|
class _DeliveryOverviewState extends State<DeliveryOverview> {
|
|
String? _selectedCarPlate;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
// Select the first car for initialization
|
|
_selectedCarPlate = widget.tour.driver.cars.firstOrNull?.plate;
|
|
}
|
|
|
|
Future<void> _loadTour() async {
|
|
Authenticated state = context.read<AuthBloc>().state as Authenticated;
|
|
context.read<TourBloc>().add(LoadTour(teamId: state.teamId));
|
|
}
|
|
|
|
Widget _carSelection() {
|
|
return SizedBox(
|
|
width: double.infinity,
|
|
height: 50,
|
|
child: ListView(
|
|
scrollDirection: Axis.horizontal,
|
|
children:
|
|
widget.tour.driver.cars.map((car) {
|
|
Color? backgroundColor;
|
|
Color? iconColor = Theme.of(context).primaryColor;
|
|
Color? textColor;
|
|
|
|
if (_selectedCarPlate == car.plate) {
|
|
backgroundColor = Theme.of(context).primaryColor;
|
|
textColor = Theme.of(context).colorScheme.onSecondary;
|
|
iconColor = Theme.of(context).colorScheme.onSecondary;
|
|
}
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.only(right: 8),
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
setState(() {
|
|
_selectedCarPlate = car.plate;
|
|
});
|
|
},
|
|
child: Chip(
|
|
backgroundColor: backgroundColor,
|
|
label: Row(
|
|
children: [
|
|
Icon(Icons.local_shipping, color: iconColor, size: 20),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 5),
|
|
child: Text(
|
|
car.plate,
|
|
style: TextStyle(color: textColor, fontSize: 12),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}).toList(),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return RefreshIndicator(
|
|
onRefresh: _loadTour,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
DeliveryInfo(tour: widget.tour),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 10, right: 10),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Text(
|
|
"Fahrten",
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
),
|
|
],
|
|
),
|
|
IconButton(icon: Icon(Icons.filter_list), onPressed: () {}),
|
|
],
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 10, right: 10, bottom: 20),
|
|
child: _carSelection(),
|
|
),
|
|
Expanded(child: DeliveryList(deliveries: widget.tour.deliveries)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|