Fixed wallets load
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:pshared/controllers/wallets.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
|
||||
import 'package:pweb/pages/dashboard/buttons/balance/carousel.dart';
|
||||
import 'package:pweb/pages/dashboard/buttons/balance/controller.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
@@ -13,26 +14,45 @@ import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
class BalanceWidget extends StatelessWidget {
|
||||
final ValueChanged<Wallet> onTopUp;
|
||||
|
||||
const BalanceWidget({super.key, required this.onTopUp});
|
||||
const BalanceWidget({
|
||||
super.key,
|
||||
required this.onTopUp,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final walletsController = context.watch<WalletsController>();
|
||||
final carousel = context.watch<CarouselIndexController>();
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
|
||||
|
||||
if (walletsController.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
|
||||
final wallets = walletsController.wallets;
|
||||
|
||||
|
||||
if (wallets.isEmpty) {
|
||||
return Center(child: Text(loc.noWalletsAvailable));
|
||||
}
|
||||
|
||||
// Ensure index is always valid when wallets list changes
|
||||
carousel.setIndex(carousel.index, wallets.length);
|
||||
|
||||
final index = carousel.index;
|
||||
final wallet = wallets[index];
|
||||
|
||||
// Single source of truth: controller
|
||||
if (walletsController.selectedWallet?.id != wallet.id) {
|
||||
walletsController.selectWallet(wallet);
|
||||
}
|
||||
|
||||
return WalletCarousel(
|
||||
wallets: wallets,
|
||||
onWalletChanged: walletsController.selectWallet,
|
||||
currentIndex: index,
|
||||
onIndexChanged: (i) {
|
||||
carousel.setIndex(i, wallets.length);
|
||||
walletsController.selectWallet(wallets[i]);
|
||||
},
|
||||
onTopUp: onTopUp,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user