Files
TravelMate/lib/components/count/balances_tab.dart
Dayron ce754c1e6c feat: Add expense management features with tabs for expenses, balances, and settlements
- Implemented ExpensesTab to display a list of expenses with details.
- Created GroupExpensesPage to manage group expenses with a tabbed interface.
- Added SettlementsTab to show optimized settlements between users.
- Developed data models for Expense and Balance, including necessary methods for serialization.
- Introduced CountRepository for Firestore interactions related to expenses.
- Added CountService to handle business logic for expenses and settlements.
- Integrated image picker for receipt uploads.
- Updated main.dart to include CountBloc and CountRepository.
- Enhanced pubspec.yaml with new dependencies for image picking and Firebase storage.

Not Tested yet
2025-10-20 19:22:57 +02:00

125 lines
3.6 KiB
Dart

import 'package:flutter/material.dart';
import '../../data/models/balance.dart';
class BalancesTab extends StatelessWidget {
final List<Balance> balances;
const BalancesTab({
super.key,
required this.balances,
});
@override
Widget build(BuildContext context) {
if (balances.isEmpty) {
return const Center(
child: Text('Aucune balance à afficher'),
);
}
return ListView.builder(
padding: const EdgeInsets.all(16),
itemCount: balances.length,
itemBuilder: (context, index) {
final balance = balances[index];
return _buildBalanceCard(context, balance);
},
);
}
Widget _buildBalanceCard(BuildContext context, Balance balance) {
final isDark = Theme.of(context).brightness == Brightness.dark;
Color balanceColor;
IconData balanceIcon;
String balanceText;
if (balance.shouldReceive) {
balanceColor = Colors.green;
balanceIcon = Icons.arrow_downward;
balanceText = 'À recevoir';
} else if (balance.shouldPay) {
balanceColor = Colors.red;
balanceIcon = Icons.arrow_upward;
balanceText = 'À payer';
} else {
balanceColor = Colors.grey;
balanceIcon = Icons.check_circle;
balanceText = 'Équilibré';
}
return Card(
margin: const EdgeInsets.only(bottom: 12),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
CircleAvatar(
radius: 24,
backgroundColor: isDark ? Colors.grey[800] : Colors.grey[200],
child: Text(
balance.userName.isNotEmpty
? balance.userName[0].toUpperCase()
: '?',
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
balance.userName,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
Text(
'Payé: ${balance.totalPaid.toStringAsFixed(2)} € • Doit: ${balance.totalOwed.toStringAsFixed(2)}',
style: TextStyle(
fontSize: 12,
color: isDark ? Colors.grey[400] : Colors.grey[600],
),
),
],
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Row(
children: [
Icon(balanceIcon, size: 16, color: balanceColor),
const SizedBox(width: 4),
Text(
'${balance.absoluteBalance.toStringAsFixed(2)}',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: balanceColor,
),
),
],
),
Text(
balanceText,
style: TextStyle(
fontSize: 12,
color: balanceColor,
),
),
],
),
],
),
),
);
}
}