|
|
|
|
@ -49,7 +49,7 @@ class GasRefillProvider extends ChangeNotifier {
|
|
|
|
|
Future<int> getRequests({
|
|
|
|
|
@required String host,
|
|
|
|
|
@required User user,
|
|
|
|
|
bool mostRecent,
|
|
|
|
|
@required bool mostRecent,
|
|
|
|
|
}) async {
|
|
|
|
|
if (isLoading == true) return -2;
|
|
|
|
|
isLoading = true;
|
|
|
|
|
@ -59,24 +59,17 @@ class GasRefillProvider extends ChangeNotifier {
|
|
|
|
|
Map<String, dynamic> body = {};
|
|
|
|
|
body["pageNumber"] = (items?.length ?? 0) ~/ pageItemNumber + 1;
|
|
|
|
|
body["pageSize"] = pageItemNumber;
|
|
|
|
|
body["mostRecent"] = mostRecent;
|
|
|
|
|
print("url:${URLs.getGasRefill}:body:$body");
|
|
|
|
|
|
|
|
|
|
response = await ApiManager.instance.post(
|
|
|
|
|
URLs.getGasRefill,
|
|
|
|
|
body: body,
|
|
|
|
|
);
|
|
|
|
|
response = await ApiManager.instance.post(URLs.getGasRefill, body: body);
|
|
|
|
|
stateCode = response.statusCode;
|
|
|
|
|
if (stateCode >= 200 && stateCode < 300) {
|
|
|
|
|
// client's request was successfully received
|
|
|
|
|
List requestsListJson = json.decode(response.body)["data"];
|
|
|
|
|
List<GasRefillModel> itemsPage = requestsListJson.map((request) => GasRefillModel.fromJson(request)).toList();
|
|
|
|
|
if (mostRecent != null) {
|
|
|
|
|
items = [];
|
|
|
|
|
} else {
|
|
|
|
|
items ??= [];
|
|
|
|
|
}
|
|
|
|
|
items ??= [];
|
|
|
|
|
items.addAll(itemsPage);
|
|
|
|
|
sortMostRecent(items, mostRecent);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
if (itemsPage.length == pageItemNumber) {
|
|
|
|
|
nextPage = true;
|
|
|
|
|
@ -96,12 +89,6 @@ class GasRefillProvider extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sortMostRecent(List<GasRefillModel> models, bool mostRecent) {
|
|
|
|
|
if (mostRecent != null) {
|
|
|
|
|
models.sort((prev, next) => (mostRecent ?? false) ? next.title.compareTo(prev.title) : prev.title.compareTo(next.title));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<int> createModel({
|
|
|
|
|
@required String host,
|
|
|
|
|
@required User user,
|
|
|
|
|
|