Finalized sorting in delivery overview
This commit is contained in:
@ -7,10 +7,10 @@ import 'package:hl_lieferservice/feature/delivery/overview/presentation/delivery
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/presentation/delivery_overview_custom_sort.dart';
|
||||
import 'package:hl_lieferservice/model/tour.dart';
|
||||
|
||||
import '../../../../model/delivery.dart';
|
||||
import '../../../authentication/bloc/auth_bloc.dart';
|
||||
import '../../../authentication/bloc/auth_state.dart';
|
||||
import '../bloc/tour_state.dart';
|
||||
|
||||
enum SortType { nameAsc, nameDesc, distance, custom }
|
||||
|
||||
class DeliveryOverview extends StatefulWidget {
|
||||
const DeliveryOverview({
|
||||
@ -28,7 +28,7 @@ class DeliveryOverview extends StatefulWidget {
|
||||
|
||||
class _DeliveryOverviewState extends State<DeliveryOverview> {
|
||||
int? _selectedCarId;
|
||||
late List<Delivery> _deliveries;
|
||||
late SortType _sortType;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -36,17 +36,7 @@ class _DeliveryOverviewState extends State<DeliveryOverview> {
|
||||
|
||||
// Select the first car for initialization
|
||||
_selectedCarId = widget.tour.driver.cars.firstOrNull?.id;
|
||||
_updateDeliveries();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant DeliveryOverview oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
_updateDeliveries();
|
||||
}
|
||||
|
||||
void _updateDeliveries() {
|
||||
_deliveries = [...widget.tour.deliveries];
|
||||
_sortType = SortType.nameAsc;
|
||||
}
|
||||
|
||||
Future<void> _loadTour() async {
|
||||
@ -102,6 +92,11 @@ class _DeliveryOverviewState extends State<DeliveryOverview> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Highlight the text of the active sorting type.
|
||||
TextStyle? _popupItemTextStyle() {
|
||||
return TextStyle(color: Theme.of(context).primaryColor, fontWeight: FontWeight.bold);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshIndicator(
|
||||
@ -128,51 +123,67 @@ class _DeliveryOverviewState extends State<DeliveryOverview> {
|
||||
),
|
||||
],
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
onSelected: (String value) {
|
||||
setState(() {
|
||||
if (value == "name-asc") {
|
||||
PopupMenuButton<SortType>(
|
||||
onSelected: (SortType value) {
|
||||
switch (value) {
|
||||
case SortType.nameAsc:
|
||||
setState(() {
|
||||
_deliveries.sort();
|
||||
_sortType = SortType.nameAsc;
|
||||
});
|
||||
}
|
||||
|
||||
if (value == "name-desc") {
|
||||
break;
|
||||
case SortType.nameDesc:
|
||||
setState(() {
|
||||
_deliveries = _deliveries.reversed.toList();
|
||||
_sortType = SortType.nameDesc;
|
||||
});
|
||||
break;
|
||||
case SortType.distance:
|
||||
setState(() {
|
||||
_sortType = SortType.distance;
|
||||
});
|
||||
break;
|
||||
case SortType.custom:
|
||||
setState(() {
|
||||
_sortType = SortType.custom;
|
||||
});
|
||||
}
|
||||
|
||||
if (value == "custom") {
|
||||
showDialog(
|
||||
context: context,
|
||||
fullscreenDialog: true,
|
||||
builder: (context) => CustomSortDialog(),
|
||||
);
|
||||
}
|
||||
|
||||
if (value == "distance") {
|
||||
// TODO: muss noch implementiert werden
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
},
|
||||
itemBuilder:
|
||||
(BuildContext context) => <PopupMenuEntry<String>>[
|
||||
PopupMenuItem<String>(
|
||||
value: 'name-asc',
|
||||
child: Text('Name (A-Z)'),
|
||||
(BuildContext context) => <PopupMenuEntry<SortType>>[
|
||||
PopupMenuItem<SortType>(
|
||||
value: SortType.nameAsc,
|
||||
child: Text(
|
||||
'Name (A-Z)',
|
||||
style: _sortType == SortType.nameAsc ? _popupItemTextStyle() : null,
|
||||
),
|
||||
),
|
||||
PopupMenuItem<String>(
|
||||
value: 'name-desc',
|
||||
child: Text('Name (Z-A)'),
|
||||
PopupMenuItem<SortType>(
|
||||
value: SortType.nameDesc,
|
||||
child: Text(
|
||||
'Name (Z-A)',
|
||||
style: _sortType == SortType.nameDesc ? _popupItemTextStyle() : null,
|
||||
),
|
||||
),
|
||||
PopupMenuItem<String>(
|
||||
value: 'distance',
|
||||
child: Text('Entfernung'),
|
||||
PopupMenuItem<SortType>(
|
||||
value: SortType.distance,
|
||||
child: Text(
|
||||
'Entfernung',
|
||||
style: _sortType == SortType.distance ? _popupItemTextStyle() : null,
|
||||
),
|
||||
),
|
||||
PopupMenuItem<String>(
|
||||
value: 'custom',
|
||||
child: Text('Eigene Sortierung'),
|
||||
PopupMenuItem<SortType>(
|
||||
value: SortType.custom,
|
||||
child: Text(
|
||||
'Eigene Sortierung',
|
||||
style: _sortType == SortType.custom ? _popupItemTextStyle() : null,
|
||||
),
|
||||
),
|
||||
],
|
||||
child: Icon(Icons.filter_list),
|
||||
@ -186,19 +197,8 @@ class _DeliveryOverviewState extends State<DeliveryOverview> {
|
||||
),
|
||||
Expanded(
|
||||
child: DeliveryList(
|
||||
distances: widget.distances,
|
||||
sortingInformation:
|
||||
(context.read<TourBloc>().state as TourLoaded)
|
||||
.sortingInformation
|
||||
.sorting,
|
||||
deliveries:
|
||||
_deliveries
|
||||
.where(
|
||||
(delivery) =>
|
||||
delivery.carId == _selectedCarId &&
|
||||
delivery.allArticlesScanned(),
|
||||
)
|
||||
.toList(),
|
||||
selectedCarId: _selectedCarId,
|
||||
sortType: _sortType,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user