Implemented new custom sort and separated the sorted view for each car
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class SortingInformation {
|
||||
String deliveryId;
|
||||
@ -18,36 +19,38 @@ class SortingInformation {
|
||||
}
|
||||
|
||||
class SortingInformationContainer {
|
||||
List<SortingInformation> sorting;
|
||||
Map<String, List<String>> cars;
|
||||
|
||||
SortingInformationContainer({required this.sorting});
|
||||
|
||||
void sort() {
|
||||
sorting.sort((a, b) => a.position.compareTo(b.position));
|
||||
}
|
||||
SortingInformationContainer({required this.cars});
|
||||
|
||||
static SortingInformationContainer fromJson(Map<String, dynamic> json) {
|
||||
SortingInformationContainer container = SortingInformationContainer(
|
||||
sorting: [],
|
||||
cars: {},
|
||||
);
|
||||
|
||||
for (final info in json["sorting"]) {
|
||||
container.sorting.add(SortingInformation.fromJson(info));
|
||||
for (final car in json["cars"].entries) {
|
||||
List<String> values = [];
|
||||
for (String value in car.value) {
|
||||
values.add(value);
|
||||
}
|
||||
|
||||
container.cars[car.key] = values;
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"sorting":
|
||||
sorting.map((info) => SortingInformation.toJson(info)).toList(),
|
||||
};
|
||||
Map<String, dynamic> cars = {};
|
||||
|
||||
for (final car in this.cars.entries) {
|
||||
cars[car.key] = car.value;
|
||||
}
|
||||
|
||||
return {"cars": cars};
|
||||
}
|
||||
|
||||
SortingInformationContainer copyWith({List<SortingInformation>? sorting}) {
|
||||
return SortingInformationContainer(
|
||||
sorting: sorting ?? this.sorting,
|
||||
);
|
||||
SortingInformationContainer copyWith({Map<String, List<String>>? sorting}) {
|
||||
return SortingInformationContainer(cars: sorting ?? cars);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user