Top Up Balance logic and Added fixes for routing

This commit is contained in:
Arseni
2025-12-05 20:29:43 +03:00
parent f7bf3138ac
commit bf39b1d401
27 changed files with 972 additions and 175 deletions

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:pweb/models/wallet.dart';
import 'package:pweb/pages/dashboard/buttons/balance/carousel.dart';
import 'package:pweb/providers/wallets.dart';
@@ -9,7 +10,9 @@ import 'package:pweb/generated/i18n/app_localizations.dart';
class BalanceWidget extends StatelessWidget {
const BalanceWidget({super.key});
final ValueChanged<Wallet> onTopUp;
const BalanceWidget({super.key, required this.onTopUp});
@override
Widget build(BuildContext context) {
@@ -30,6 +33,7 @@ class BalanceWidget extends StatelessWidget {
WalletCarousel(
wallets: wallets,
onWalletChanged: walletsProvider.selectWallet,
onTopUp: onTopUp,
);
}
}

View File

@@ -12,10 +12,12 @@ import 'package:pweb/providers/wallets.dart';
class WalletCard extends StatelessWidget {
final Wallet wallet;
final VoidCallback onTopUp;
const WalletCard({
super.key,
required this.wallet,
required this.onTopUp,
});
@override
@@ -43,7 +45,7 @@ class WalletCard extends StatelessWidget {
),
BalanceAddFunds(
onTopUp: () {
// TODO: Implement top-up functionality
onTopUp();
},
),
],
@@ -51,4 +53,4 @@ class WalletCard extends StatelessWidget {
),
);
}
}
}

View File

@@ -12,11 +12,13 @@ import 'package:pweb/providers/carousel.dart';
class WalletCarousel extends StatefulWidget {
final List<Wallet> wallets;
final ValueChanged<Wallet> onWalletChanged;
final ValueChanged<Wallet> onTopUp;
const WalletCarousel({
super.key,
required this.wallets,
required this.onWalletChanged,
required this.onTopUp,
});
@override
@@ -33,6 +35,11 @@ class _WalletCarouselState extends State<WalletCarousel> {
_pageController = PageController(
viewportFraction: WalletCardConfig.viewportFraction,
);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (widget.wallets.isNotEmpty) {
widget.onWalletChanged(widget.wallets[_currentPage]);
}
});
}
@override
@@ -83,7 +90,10 @@ class _WalletCarouselState extends State<WalletCarousel> {
itemBuilder: (context, index) {
return Padding(
padding: WalletCardConfig.cardPadding,
child: WalletCard(wallet: widget.wallets[index]),
child: WalletCard(
wallet: widget.wallets[index],
onTopUp: () => widget.onTopUp(widget.wallets[index]),
),
);
},
),
@@ -110,4 +120,4 @@ class _WalletCarouselState extends State<WalletCarousel> {
],
);
}
}
}

View File

@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:pshared/models/payment/type.dart';
import 'package:pshared/models/recipient/recipient.dart';
import 'package:pweb/models/wallet.dart';
import 'package:pweb/pages/dashboard/buttons/balance/balance.dart';
import 'package:pweb/pages/dashboard/buttons/buttons.dart';
import 'package:pweb/pages/dashboard/payouts/multiple/title.dart';
@@ -22,11 +23,13 @@ class AppSpacing {
class DashboardPage extends StatefulWidget {
final ValueChanged<Recipient> onRecipientSelected;
final void Function(PaymentType type) onGoToPaymentWithoutRecipient;
final ValueChanged<Wallet> onTopUp;
const DashboardPage({
super.key,
required this.onRecipientSelected,
required this.onGoToPaymentWithoutRecipient,
required this.onTopUp,
});
@override
@@ -75,7 +78,9 @@ class _DashboardPageState extends State<DashboardPage> {
],
),
const SizedBox(height: AppSpacing.medium),
BalanceWidget(),
BalanceWidget(
onTopUp: widget.onTopUp,
),
const SizedBox(height: AppSpacing.small),
if (_showContainerMultiple) TitleMultiplePayout(),
const SizedBox(height: AppSpacing.medium),