156 lines
4.9 KiB
Dart
156 lines
4.9 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) {
|
|
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: Colors.white,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: Colors.grey.shade200),
|
|
boxShadow: [
|
|
BoxShadow(color: Colors.black.withOpacity(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: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16, color: Colors.black87),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
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),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
);
|
|
}
|
|
}
|