Finished custom sorting of deliveries
This commit is contained in:
54
lib/feature/delivery/overview/model/sorting_information.dart
Normal file
54
lib/feature/delivery/overview/model/sorting_information.dart
Normal file
@ -0,0 +1,54 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class SortingInformation {
|
||||
String deliveryId;
|
||||
int position;
|
||||
|
||||
SortingInformation({required this.deliveryId, required this.position});
|
||||
|
||||
static Map<String, dynamic> toJson(SortingInformation info) {
|
||||
return {"delivery_id": info.deliveryId, "position": info.position};
|
||||
}
|
||||
|
||||
static SortingInformation fromJson(Map<String, dynamic> json) {
|
||||
return SortingInformation(
|
||||
deliveryId: json["delivery_id"].toString(),
|
||||
position: json["position"],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SortingInformationContainer {
|
||||
List<SortingInformation> sorting;
|
||||
|
||||
SortingInformationContainer({required this.sorting});
|
||||
|
||||
void sort() {
|
||||
sorting.sort((a, b) => a.position.compareTo(b.position));
|
||||
}
|
||||
|
||||
static SortingInformationContainer fromJson(Map<String, dynamic> json) {
|
||||
SortingInformationContainer container = SortingInformationContainer(
|
||||
sorting: [],
|
||||
);
|
||||
|
||||
for (final info in json["sorting"]) {
|
||||
container.sorting.add(SortingInformation.fromJson(info));
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"sorting":
|
||||
sorting.map((info) => SortingInformation.toJson(info)).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
SortingInformationContainer copyWith({List<SortingInformation>? sorting}) {
|
||||
return SortingInformationContainer(
|
||||
sorting: sorting ?? this.sorting,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user