completed velocity integration
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:qpay/http/http.dart';
|
||||
import 'package:qpay/models/api_response.dart';
|
||||
import 'package:qpay/models/pageable_model.dart';
|
||||
|
||||
part 'home_controller.freezed.dart';
|
||||
@@ -93,24 +94,13 @@ class HomeController extends ChangeNotifier {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _showErrorSnackBar(String? message) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message.toString()),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
backgroundColor: Colors.deepOrange,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> getAccounts() async {
|
||||
Future<ApiResponse<List<Account>>> getAccounts() async {
|
||||
model.accounts = getFakeAccounts();
|
||||
if (!_disposed) notifyListeners();
|
||||
return ApiResponse.success(model.accounts);
|
||||
}
|
||||
|
||||
Future<void> getProviders() async {
|
||||
Future<ApiResponse<List<BillProvider>>> getProviders() async {
|
||||
try {
|
||||
model.filterableProviders = getFakeProviders();
|
||||
model.transactions = getFakeTransactions();
|
||||
@@ -125,19 +115,22 @@ class HomeController extends ChangeNotifier {
|
||||
if (model.providers.isNotEmpty) {
|
||||
updateSelectedProvider(model.providers[0]);
|
||||
}
|
||||
|
||||
model.isLoading = false;
|
||||
if (!_disposed) notifyListeners();
|
||||
return ApiResponse.success(model.providers);
|
||||
} catch (e, s) {
|
||||
logger.e(e);
|
||||
logger.e(s);
|
||||
_showErrorSnackBar(
|
||||
"Problem fetching providers, are you connected to the internet?",
|
||||
);
|
||||
model.errorMessage = e.toString();
|
||||
model.providers = [];
|
||||
model.filterableProviders = [];
|
||||
model.isLoading = false;
|
||||
if (!_disposed) notifyListeners();
|
||||
return ApiResponse.failure(
|
||||
"Problem fetching providers, are you connected to the internet?",
|
||||
);
|
||||
}
|
||||
|
||||
model.isLoading = false;
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
void updateSelectedProvider(BillProvider provider) {
|
||||
@@ -148,9 +141,8 @@ class HomeController extends ChangeNotifier {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> getTransactions(String userId) async {
|
||||
Future<ApiResponse<List<Map<String, dynamic>>>> getTransactions(String userId) async {
|
||||
model.isLoading = true;
|
||||
// model.transactions = getFakeTransactions();
|
||||
if (!_disposed) notifyListeners();
|
||||
|
||||
try {
|
||||
@@ -163,20 +155,23 @@ class HomeController extends ChangeNotifier {
|
||||
model.transactions = pageableModel.content
|
||||
.map((e) => e as Map<String, dynamic>)
|
||||
.toList();
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
_showErrorSnackBar(
|
||||
"Problem fetching transactions, are you connected to the internet?",
|
||||
);
|
||||
model.errorMessage = e.toString();
|
||||
model.transactions = [];
|
||||
} finally {
|
||||
|
||||
model.isLoading = false;
|
||||
if (!_disposed) notifyListeners();
|
||||
return ApiResponse.success(model.transactions);
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
model.errorMessage = e.toString();
|
||||
model.transactions = [];
|
||||
model.isLoading = false;
|
||||
if (!_disposed) notifyListeners();
|
||||
return ApiResponse.failure(
|
||||
"Problem fetching transactions, are you connected to the internet?",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getCategories() async {
|
||||
Future<ApiResponse<List<Category>>> getCategories() async {
|
||||
// activate skeletonizer
|
||||
model.categories = getFakeCategoryData();
|
||||
model.isLoading = true;
|
||||
@@ -190,20 +185,23 @@ class HomeController extends ChangeNotifier {
|
||||
if (model.categories.isNotEmpty) {
|
||||
updateSelectedCategory(model.categories[0]);
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
logger.e(e);
|
||||
_showErrorSnackBar(
|
||||
"Problem fetching categories, are you connected to the internet?",
|
||||
);
|
||||
model.errorMessage = e.toString();
|
||||
model.categories = [];
|
||||
} finally {
|
||||
|
||||
model.isLoading = false;
|
||||
if (!_disposed) notifyListeners();
|
||||
return ApiResponse.success(model.categories);
|
||||
} on Exception catch (e) {
|
||||
logger.e(e);
|
||||
model.errorMessage = e.toString();
|
||||
model.categories = [];
|
||||
model.isLoading = false;
|
||||
if (!_disposed) notifyListeners();
|
||||
return ApiResponse.failure(
|
||||
"Problem fetching categories, are you connected to the internet?",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateSelectedCategory(Category? category) async {
|
||||
void updateSelectedCategory(Category? category) {
|
||||
if (category == null) {
|
||||
model.filterableProviders = model.providers;
|
||||
if (!_disposed) notifyListeners();
|
||||
|
||||
Reference in New Issue
Block a user