Files
Kifi/kifi-app/lib/features/dashboard/presentation/widgets/swipeable_account_card.dart

171 lines
5.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:lucide_icons/lucide_icons.dart';
class CarouselItemData {
final String title;
final String subtitle;
final double amount;
final Color color;
final IconData icon;
final VoidCallback? onTap;
CarouselItemData({
required this.title,
this.subtitle = '',
required this.amount,
required this.color,
required this.icon,
this.onTap,
});
}
class SwipeableAccountCard extends StatefulWidget {
final List<CarouselItemData> items;
const SwipeableAccountCard({super.key, required this.items});
@override
State<SwipeableAccountCard> createState() => _SwipeableAccountCardState();
}
class _SwipeableAccountCardState extends State<SwipeableAccountCard> {
int _currentPage = 0;
late PageController _pageController;
@override
void initState() {
super.initState();
_pageController = PageController(initialPage: 0);
}
@override
void dispose() {
_pageController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
if (widget.items.isEmpty) {
return const SizedBox.shrink();
}
return Column(
children: [
SizedBox(
height: 85, // adjusted height for the row-based card
child: PageView.builder(
controller: _pageController,
onPageChanged: (index) {
setState(() {
_currentPage = index;
});
},
itemCount: widget.items.length,
itemBuilder: (context, index) {
final item = widget.items[index];
return GestureDetector(
onTap: item.onTap,
child: Container(
margin: const EdgeInsets.symmetric(
horizontal: 4.0,
vertical: 4.0,
),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: Theme.of(
context,
).dividerColor.withOpacity(isDark ? 0.1 : 0.2),
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(isDark ? 0.2 : 0.02),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: item.color.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(item.icon, color: item.color, size: 20),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
item.title,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
if (item.subtitle.isNotEmpty) ...[
const SizedBox(height: 4),
Text(
item.subtitle,
style: TextStyle(
color: Colors.grey.shade600,
fontSize: 12,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
],
),
),
Text(
'Rs. ${item.amount.toStringAsFixed(0)}',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: Theme.of(context).textTheme.bodyLarge?.color,
),
),
],
),
),
);
},
),
),
if (widget.items.length > 1) ...[
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(
widget.items.length,
(index) => Container(
margin: const EdgeInsets.symmetric(horizontal: 4.0),
width: 8.0,
height: 8.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: _currentPage == index
? widget.items[index].color
: Colors.grey.withOpacity(0.3),
),
),
),
),
],
],
);
}
}