prototype complete
This commit is contained in:
@@ -8,7 +8,7 @@ part 'home_controller.freezed.dart';
|
||||
part 'home_controller.g.dart';
|
||||
|
||||
class HomeScreenModel {
|
||||
List<dynamic> transactions = [];
|
||||
List<Map<String, dynamic>> transactions = [];
|
||||
List<Category> categories = [];
|
||||
List<BillProvider> providers = [];
|
||||
List<BillProvider> filterableProviders = [];
|
||||
@@ -51,6 +51,7 @@ abstract class BillProvider with _$BillProvider {
|
||||
required String image,
|
||||
required String label,
|
||||
required String category,
|
||||
required String? accountFieldName,
|
||||
}) = _BillProvider;
|
||||
|
||||
factory BillProvider.fromJson(Map<String, dynamic> json) =>
|
||||
@@ -60,11 +61,26 @@ abstract class BillProvider with _$BillProvider {
|
||||
class HomeController extends ChangeNotifier {
|
||||
final HomeScreenModel model = HomeScreenModel();
|
||||
final Http http = Http();
|
||||
BuildContext context;
|
||||
|
||||
HomeController(this.context);
|
||||
|
||||
void _showErrorSnackBar(String? message) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message.toString()),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
backgroundColor: Colors.deepOrange,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> getProviders() async {
|
||||
model.providers = getFakeProviders();
|
||||
try {
|
||||
model.isLoading = true;
|
||||
notifyListeners();
|
||||
|
||||
List<dynamic> response = await http.get('/providers');
|
||||
model.providers = response.map((e) => BillProvider.fromJson(e)).toList();
|
||||
@@ -75,6 +91,9 @@ class HomeController extends ChangeNotifier {
|
||||
}
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
_showErrorSnackBar(
|
||||
"Problem fetching providers, are you connected to the internet?",
|
||||
);
|
||||
model.errorMessage = e.toString();
|
||||
model.providers = [];
|
||||
model.filterableProviders = [];
|
||||
@@ -92,12 +111,39 @@ class HomeController extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> getTransactions(String userId) async {
|
||||
model.isLoading = true;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
List<dynamic> response = await http.get(
|
||||
'/transaction?userId=$userId&type=REQUEST',
|
||||
);
|
||||
model.transactions =
|
||||
response.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;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getCategories() async {
|
||||
// activate skeletonizer
|
||||
model.categories = getFakeCategoryData();
|
||||
model.transactions = getFakeTransactions();
|
||||
// model.filterableProviders = getFakeProviders();
|
||||
model.isLoading = true;
|
||||
notifyListeners();
|
||||
|
||||
// Simulate fetching categories
|
||||
try {
|
||||
model.isLoading = true;
|
||||
List<dynamic> response = await http.get('/categories');
|
||||
model.categories = response.map((e) => Category.fromJson(e)).toList();
|
||||
|
||||
@@ -106,6 +152,9 @@ class HomeController extends ChangeNotifier {
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
logger.e(e);
|
||||
_showErrorSnackBar(
|
||||
"Problem fetching categories, are you connected to the internet?",
|
||||
);
|
||||
model.errorMessage = e.toString();
|
||||
model.categories = [];
|
||||
} finally {
|
||||
@@ -131,6 +180,37 @@ class HomeController extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> getFakeTransactions() {
|
||||
return [
|
||||
{
|
||||
"id": "77b2c479-b803-49fc-b5c3-acbf52cba633",
|
||||
"trace": "22a3044b-8f53-4e43-b4f5-c77dcec48d2d",
|
||||
"amount": 25.0,
|
||||
"charge": 0.0,
|
||||
"gatewayCharge": 0.25,
|
||||
"tax": 0.5,
|
||||
"totalAmount": 25.75,
|
||||
"reference": "c838136c-c015-4a0b-9c7c-52f127c8c109",
|
||||
"paymentProcessorLabel": "MPGS",
|
||||
"paymentProcessorImage": "visa-mastercard.png",
|
||||
"debitPhone": "",
|
||||
"debitAccount": "",
|
||||
"debitCurrency": "USD",
|
||||
"debitRef": "peak",
|
||||
"creditPhone": "",
|
||||
"creditAccount": "07088597534",
|
||||
"billClientId": "powertel_zesa",
|
||||
"billName": "Zesa",
|
||||
"type": "REQUEST",
|
||||
"authType": "WEB",
|
||||
"errorMessage": "",
|
||||
"responseCode": "00",
|
||||
"status": "SUCCESS",
|
||||
"sdkActionId": "0aa0d90d-6132-48a7-a5d8-e796f757c73f",
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
List<BillProvider> getFakeProviders() {
|
||||
return [
|
||||
BillProvider(
|
||||
@@ -148,6 +228,7 @@ class HomeController extends ChangeNotifier {
|
||||
image: 'econet.png',
|
||||
label: '',
|
||||
category: '',
|
||||
accountFieldName: '',
|
||||
),
|
||||
];
|
||||
}
|
||||
@@ -156,17 +237,11 @@ class HomeController extends ChangeNotifier {
|
||||
List<Category> getFakeCategoryData() {
|
||||
return [
|
||||
Category(
|
||||
name: 'Electricity',
|
||||
name: 'Airtime',
|
||||
description: 'Pay your electricity bills easily',
|
||||
image: 'assets/images/electricity.png',
|
||||
label: 'Electricity',
|
||||
),
|
||||
Category(
|
||||
name: 'Internet',
|
||||
description: 'Pay your internet bills easily',
|
||||
image: 'assets/images/internet.png',
|
||||
label: 'Internet',
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user