Implemented new custom sort and separated the sorted view for each car
This commit is contained in:
@ -26,18 +26,19 @@ class _DeliveryListState extends State<DeliveryList> {
|
||||
|
||||
Widget _showCustomSortedList(
|
||||
List<Delivery> deliveries,
|
||||
List<SortingInformation> sortingInformation,
|
||||
List<String> sortingInformation,
|
||||
Map<String, double> distances,
|
||||
) {
|
||||
List<SortingInformation> sorted = [...sortingInformation];
|
||||
sorted.sort((a, b) => a.position.compareTo(b.position));
|
||||
|
||||
return ListView.separated(
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
separatorBuilder: (context, index) => const Divider(height: 0),
|
||||
itemBuilder: (context, index) {
|
||||
SortingInformation info = sorted[index];
|
||||
String id = sortingInformation[index];
|
||||
Delivery delivery = deliveries.firstWhere(
|
||||
(delivery) => info.deliveryId == delivery.id,
|
||||
(delivery) =>
|
||||
id == delivery.id &&
|
||||
delivery.carId == widget.selectedCarId,
|
||||
);
|
||||
|
||||
return DeliveryListItem(
|
||||
@ -45,7 +46,7 @@ class _DeliveryListState extends State<DeliveryList> {
|
||||
distance: distances[delivery.id] ?? 0.0,
|
||||
);
|
||||
},
|
||||
itemCount: sorted.length,
|
||||
itemCount: sortingInformation.length,
|
||||
);
|
||||
}
|
||||
|
||||
@ -60,12 +61,24 @@ class _DeliveryListState extends State<DeliveryList> {
|
||||
.where(
|
||||
(delivery) =>
|
||||
delivery.carId == widget.selectedCarId &&
|
||||
delivery.allArticlesScanned() || delivery.state == DeliveryState.finished,
|
||||
delivery.allArticlesScanned() &&
|
||||
delivery.state != DeliveryState.finished,
|
||||
)
|
||||
.toList();
|
||||
|
||||
List<Delivery> finishedDeliveries =
|
||||
currentState.tour.deliveries
|
||||
.where(
|
||||
(delivery) =>
|
||||
delivery.state == DeliveryState.finished &&
|
||||
delivery.carId == widget.selectedCarId,
|
||||
)
|
||||
.toList();
|
||||
|
||||
if (deliveries.isEmpty) {
|
||||
return ListView(
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
Center(child: const Text("Keine Auslieferungen gefunden")),
|
||||
],
|
||||
@ -75,8 +88,8 @@ class _DeliveryListState extends State<DeliveryList> {
|
||||
switch (widget.sortType) {
|
||||
case SortType.custom:
|
||||
return _showCustomSortedList(
|
||||
deliveries,
|
||||
currentState.sortingInformation.sorting,
|
||||
currentState.tour.deliveries,
|
||||
currentState.sortingInformation[widget.selectedCarId.toString()] ?? [],
|
||||
currentState.distances ?? {},
|
||||
);
|
||||
|
||||
@ -101,8 +114,12 @@ class _DeliveryListState extends State<DeliveryList> {
|
||||
break;
|
||||
}
|
||||
|
||||
//deliveries.addAll(finishedDeliveries);
|
||||
|
||||
return ListView.separated(
|
||||
separatorBuilder: (context, index) => const Divider(height: 0),
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
itemBuilder: (context, index) {
|
||||
Delivery delivery = deliveries[index];
|
||||
|
||||
|
||||
@ -101,8 +101,8 @@ class _DeliveryOverviewState extends State<DeliveryOverview> {
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: _loadTour,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
child: ListView(
|
||||
//crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
DeliveryInfo(tour: widget.tour),
|
||||
Padding(
|
||||
@ -150,7 +150,7 @@ class _DeliveryOverviewState extends State<DeliveryOverview> {
|
||||
showDialog(
|
||||
context: context,
|
||||
fullscreenDialog: true,
|
||||
builder: (context) => CustomSortDialog(),
|
||||
builder: (context) => CustomSortDialog(selectedCarId: _selectedCarId,),
|
||||
);
|
||||
break;
|
||||
}
|
||||
@ -195,11 +195,9 @@ class _DeliveryOverviewState extends State<DeliveryOverview> {
|
||||
padding: const EdgeInsets.only(left: 10, right: 10, bottom: 20),
|
||||
child: _carSelection(),
|
||||
),
|
||||
Expanded(
|
||||
child: DeliveryList(
|
||||
selectedCarId: _selectedCarId,
|
||||
sortType: _sortType,
|
||||
),
|
||||
DeliveryList(
|
||||
selectedCarId: _selectedCarId,
|
||||
sortType: _sortType,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@ -3,33 +3,34 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/bloc/tour_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/bloc/tour_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/bloc/tour_state.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/util.dart';
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
|
||||
import '../model/sorting_information.dart';
|
||||
|
||||
class CustomSortDialog extends StatefulWidget {
|
||||
const CustomSortDialog({super.key});
|
||||
const CustomSortDialog({super.key, this.selectedCarId});
|
||||
|
||||
final int? selectedCarId;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _CustomSortDialogState();
|
||||
}
|
||||
|
||||
class _CustomSortDialogState extends State<CustomSortDialog> {
|
||||
late List<SortingInformation> _localSortedList;
|
||||
late List<String> _localSortedList;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final state = context.read<TourBloc>().state;
|
||||
if (state is TourLoaded) {
|
||||
_localSortedList = [...state.sortingInformation.sorting];
|
||||
_localSortedList.sort((a, b) => a.position.compareTo(b.position));
|
||||
_localSortedList = [
|
||||
...state.sortingInformation[widget.selectedCarId.toString()] ?? [],
|
||||
];
|
||||
} else {
|
||||
_localSortedList = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Widget _information() {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
@ -68,49 +69,49 @@ class _CustomSortDialogState extends State<CustomSortDialog> {
|
||||
child: ReorderableListView(
|
||||
onReorder: (oldIndex, newIndex) {
|
||||
setState(() {
|
||||
if (oldIndex < newIndex) {
|
||||
newIndex -= 1;
|
||||
}
|
||||
final SortingInformation item = _localSortedList.removeAt(oldIndex);
|
||||
_localSortedList.insert(newIndex, item);
|
||||
_localSortedList = reorderList(
|
||||
_localSortedList,
|
||||
oldIndex,
|
||||
newIndex,
|
||||
);
|
||||
});
|
||||
|
||||
context.read<TourBloc>().add(
|
||||
ReorderDeliveryEvent(
|
||||
newPosition: newIndex,
|
||||
oldPosition: oldIndex,
|
||||
carId: widget.selectedCarId.toString(),
|
||||
),
|
||||
);
|
||||
},
|
||||
children:
|
||||
_localSortedList.map((info) {
|
||||
Delivery delivery = currentState.tour.deliveries.firstWhere(
|
||||
(delivery) => delivery.id == info.deliveryId,
|
||||
);
|
||||
SortingInformation information = currentState
|
||||
.sortingInformation
|
||||
.sorting
|
||||
.firstWhere((info) => info.deliveryId == delivery.id);
|
||||
_localSortedList
|
||||
.map((id) {
|
||||
Delivery delivery = currentState.tour.deliveries
|
||||
.firstWhere((delivery) => delivery.id == id);
|
||||
int pos = _localSortedList.indexOf(id) + 1;
|
||||
|
||||
return ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
child: Text(
|
||||
"${information.position + 1}",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onSecondary,
|
||||
return ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
child: Text(
|
||||
"$pos",
|
||||
style: TextStyle(
|
||||
color:
|
||||
Theme.of(context).colorScheme.onSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(delivery.customer.name),
|
||||
subtitle: Text(
|
||||
delivery.customer.address.toString(),
|
||||
style: TextStyle(fontSize: 11),
|
||||
),
|
||||
trailing: Icon(Icons.drag_handle),
|
||||
key: Key("reorder-item-${delivery.id}"),
|
||||
);
|
||||
}).toList(),
|
||||
title: Text(delivery.customer.name),
|
||||
subtitle: Text(
|
||||
delivery.customer.address.toString(),
|
||||
style: TextStyle(fontSize: 11),
|
||||
),
|
||||
trailing: Icon(Icons.drag_handle),
|
||||
key: Key("reorder-item-${delivery.id}"),
|
||||
);
|
||||
})
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -28,6 +28,8 @@ class _DeliveryOverviewPageState extends State<DeliveryOverviewPage> {
|
||||
);
|
||||
}
|
||||
|
||||
debugPrint(state.toString());
|
||||
|
||||
return Container();
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user