added zwg support
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -8,7 +9,6 @@ import 'package:qpay/screens/home/home_controller.dart';
|
||||
import 'package:qpay/screens/receipt/receipt_controller.dart';
|
||||
import 'package:qpay/screens/transaction_controller.dart';
|
||||
import 'package:qpay/screens/transactions/transaction_model.dart' as txn;
|
||||
import 'package:qpay/widgets/app_snack_bar.dart';
|
||||
import 'package:qpay/widgets/transaction_item_widget.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -28,8 +28,8 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
||||
late final router = GoRouter.of(context);
|
||||
|
||||
bool _isLoggedIn = false;
|
||||
bool _isZWGSelected = false;
|
||||
String initials = '';
|
||||
String _selectedCurrency = 'USD';
|
||||
|
||||
late AnimationController _providersAnimController;
|
||||
late Animation<Offset> _providersSlideAnimation;
|
||||
@@ -107,7 +107,10 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
||||
homeController = HomeController(context);
|
||||
await homeController.getAccounts();
|
||||
await homeController.getCategories();
|
||||
await homeController.getProviders(_isZWGSelected ? "ZWG" : "USD");
|
||||
await homeController.getProviders(_selectedCurrency);
|
||||
|
||||
transactionController.model.formData = transactionController.model.formData
|
||||
.copyWith(debitCurrency: _selectedCurrency);
|
||||
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
|
||||
@@ -127,10 +130,22 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
||||
await homeController.getTransactions(prefs.getString("userId")!);
|
||||
}
|
||||
|
||||
void _onCurrencySelected(String currency) {
|
||||
if (_selectedCurrency == currency) return;
|
||||
|
||||
setState(() {
|
||||
_selectedCurrency = currency;
|
||||
});
|
||||
|
||||
homeController.getProviders(currency);
|
||||
|
||||
transactionController.updateCurrency(currency);
|
||||
}
|
||||
|
||||
Future<void> _onRefresh() async {
|
||||
await homeController.getAccounts();
|
||||
await homeController.getCategories();
|
||||
await homeController.getProviders(_isZWGSelected ? "ZWG" : "USD");
|
||||
await homeController.getProviders(_selectedCurrency);
|
||||
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
if (prefs.getString("userId") != null) {
|
||||
@@ -153,9 +168,21 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
||||
|
||||
/// Handles the repeat action for a transaction.
|
||||
Future<void> _repeatTransaction(Map<String, dynamic> item) async {
|
||||
final receiptController = ReceiptController(context);
|
||||
final transaction = txn.TransactionModel.fromJson(item);
|
||||
await receiptController.repeatTransaction(transaction);
|
||||
try {
|
||||
final receiptController = ReceiptController(context);
|
||||
final transaction = txn.TransactionModel.fromJson(item);
|
||||
await receiptController.repeatTransaction(transaction);
|
||||
} catch (e, s) {
|
||||
if (kDebugMode) {
|
||||
print(e);
|
||||
print(s);
|
||||
}
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('Error repeating transaction')));
|
||||
}
|
||||
}
|
||||
if (mounted) {
|
||||
context.push('/make-payment');
|
||||
}
|
||||
@@ -370,7 +397,11 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
||||
_buildLoginPrompt(theme, isDark),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
if (_isLoggedIn) const AccountBalanceWidget(),
|
||||
if (_isLoggedIn)
|
||||
AccountBalanceWidget(
|
||||
selectedCurrency: _selectedCurrency,
|
||||
onCurrencySelected: _onCurrencySelected,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
|
||||
Reference in New Issue
Block a user