import 'package:flutter/material.dart'; import 'package:flutter_lucide/flutter_lucide.dart'; import 'package:get/get.dart'; import 'package:marco/controller/project_controller.dart'; import 'package:marco/helpers/utils/mixins/ui_mixin.dart'; import 'package:marco/helpers/widgets/my_card.dart'; import 'package:marco/helpers/widgets/my_container.dart'; import 'package:marco/helpers/widgets/my_spacing.dart'; import 'package:marco/helpers/widgets/my_text.dart'; class FinanceScreen extends StatefulWidget { const FinanceScreen({super.key}); @override State createState() => _FinanceScreenState(); } class _FinanceScreenState extends State with UIMixin { final projectController = Get.find(); @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, appBar: AppBar( title: const Text("Finance"), centerTitle: true, backgroundColor: Colors.white, elevation: 0.5, foregroundColor: Colors.black, ), body: SingleChildScrollView( padding: const EdgeInsets.all(12), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ _buildFinanceStatCards(context), ], ), ), ); } Widget _buildFinanceStatCards(BuildContext context) { final stats = [ _FinanceStatItem( LucideIcons.badge_dollar_sign, "Expense", contentTheme.info, "/dashboard/expense-main-page", ), _FinanceStatItem( LucideIcons.receipt_text, "Payment Request", contentTheme.primary, "/dashboard/payment-request", ), _FinanceStatItem( LucideIcons.wallet, "Advance Payment", contentTheme.warning, "/dashboard/advance-payment", ), ]; final projectSelected = projectController.selectedProject != null; return LayoutBuilder( builder: (context, constraints) { int crossAxisCount = (constraints.maxWidth ~/ 100).clamp(2, 6); double cardWidth = (constraints.maxWidth - (crossAxisCount - 1) * 6) / crossAxisCount; return Wrap( spacing: 6, runSpacing: 6, alignment: WrapAlignment.start, children: stats .map((stat) => _buildFinanceCard(stat, projectSelected, cardWidth)) .toList(), ); }, ); } Widget _buildFinanceCard( _FinanceStatItem statItem, bool isProjectSelected, double width) { const double cardHeight = 80; final bool isEnabled = isProjectSelected; return Opacity( opacity: isEnabled ? 1.0 : 0.4, child: IgnorePointer( ignoring: !isEnabled, child: InkWell( borderRadius: BorderRadius.circular(8), onTap: () => _onCardTap(statItem, isEnabled), child: MyCard.bordered( width: width, height: cardHeight, paddingAll: 12, borderRadiusAll: 8, border: Border.all(color: Colors.grey.withOpacity(0.15)), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ MyContainer.rounded( paddingAll: 6, color: statItem.color.withOpacity(0.1), child: Icon( statItem.icon, size: 18, color: statItem.color, ), ), MySpacing.height(8), MyText.bodySmall( statItem.title, fontWeight: 600, color: Colors.black87, textAlign: TextAlign.center, ), ], ), ), ), ), ); } void _onCardTap(_FinanceStatItem statItem, bool isEnabled) { if (!isEnabled) { Get.defaultDialog( title: "No Project Selected", middleText: "Please select a project before accessing this section.", confirm: ElevatedButton( onPressed: () => Get.back(), child: const Text("OK"), ), ); return; } Get.toNamed(statItem.route); } } class _FinanceStatItem { final IconData icon; final String title; final Color color; final String route; _FinanceStatItem( this.icon, this.title, this.color, this.route, ); }