72 lines
2.0 KiB
Dart
72 lines
2.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:pshared/models/payment/wallet.dart';
|
|
import 'package:pweb/pages/dashboard/buttons/balance/card.dart';
|
|
import 'package:pweb/pages/dashboard/buttons/balance/config.dart';
|
|
import 'package:pweb/pages/dashboard/buttons/balance/indicator.dart';
|
|
|
|
|
|
class WalletCarousel extends StatelessWidget {
|
|
final List<Wallet> wallets;
|
|
final int currentIndex;
|
|
final ValueChanged<int> onIndexChanged;
|
|
final ValueChanged<Wallet> onTopUp;
|
|
|
|
const WalletCarousel({
|
|
super.key,
|
|
required this.wallets,
|
|
required this.currentIndex,
|
|
required this.onIndexChanged,
|
|
required this.onTopUp,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (wallets.isEmpty) {
|
|
return const SizedBox.shrink();
|
|
}
|
|
|
|
final safeIndex = currentIndex.clamp(0, wallets.length - 1);
|
|
final wallet = wallets[safeIndex];
|
|
|
|
return Column(
|
|
children: [
|
|
SizedBox(
|
|
height: WalletCardConfig.cardHeight,
|
|
child: Padding(
|
|
padding: WalletCardConfig.cardPadding,
|
|
child: WalletCard(
|
|
wallet: wallet,
|
|
onTopUp: () => onTopUp(wallet),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
IconButton(
|
|
onPressed: safeIndex > 0
|
|
? () => onIndexChanged(safeIndex - 1)
|
|
: null,
|
|
icon: const Icon(Icons.arrow_back),
|
|
),
|
|
const SizedBox(width: 16),
|
|
CarouselIndicator(
|
|
itemCount: wallets.length,
|
|
index: safeIndex,
|
|
),
|
|
const SizedBox(width: 16),
|
|
IconButton(
|
|
onPressed: safeIndex < wallets.length - 1
|
|
? () => onIndexChanged(safeIndex + 1)
|
|
: null,
|
|
icon: const Icon(Icons.arrow_forward),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|