improving ui elements
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:qpay/http/http.dart';
|
||||
import 'package:qpay/models/pageable_model.dart';
|
||||
|
||||
class HistoryModel {
|
||||
PageableModel? pageableModel;
|
||||
|
||||
List<Map<String, dynamic>> transactions = [];
|
||||
bool isLoading = false;
|
||||
String? errorMessage;
|
||||
@@ -26,16 +29,29 @@ class HistoryController extends ChangeNotifier {
|
||||
|
||||
Future<void> getTransactions(Map<String, String> params) async {
|
||||
model.isLoading = true;
|
||||
model.transactions = getFakeTransactions();
|
||||
if (params['page'] == '0') {
|
||||
model.transactions = getFakeTransactions();
|
||||
}
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
params['type'] = 'REQUEST';
|
||||
List<dynamic> response = await http.get(
|
||||
Map<String, dynamic> response = await http.get(
|
||||
'/transaction?${buildQueryParameters(params)}',
|
||||
);
|
||||
|
||||
if (params['page'] == '0') {
|
||||
model.transactions = [];
|
||||
}
|
||||
|
||||
model.pageableModel = PageableModel.fromJson(response);
|
||||
|
||||
// pagination adds to current list instead of replacing it
|
||||
model.transactions =
|
||||
response.map((e) => e as Map<String, dynamic>).toList();
|
||||
model.transactions +
|
||||
model.pageableModel!.content
|
||||
.map((e) => e as Map<String, dynamic>)
|
||||
.toList();
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
_showErrorSnackBar(
|
||||
|
||||
Reference in New Issue
Block a user