| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import 'package:flutter/material.dart';
- import 'package:flutter/widgets.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:intl/intl.dart';
- import 'package:ristoris/providers/customer_provider.dart';
- class PaymentsTab extends ConsumerWidget {
- final int idCliente;
- final ThemeData theme;
- const PaymentsTab({required this.idCliente, required this.theme});
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- final paysAsync = ref.watch(customerPaymentsProvider(idCliente));
- return paysAsync.when(
- data: (pays) {
- if (pays.isEmpty) return const Center(child: Text('Nessuna scadenza'));
- return ListView.builder(
- padding: const EdgeInsets.all(8),
- itemCount: pays.length,
- itemBuilder: (_, i) {
- final p = pays[i];
- return Card(
- margin: const EdgeInsets.symmetric(vertical: 4),
- child: Padding(
- padding: const EdgeInsets.all(12),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _row('Fattura N.', p.numDoc ?? '-'),
- _row('Data fatt.', _formatDate(p.dataDoc)),
- _row('Data scad', _formatDate(p.dataScadenza)),
- _row('Totale fattura', _formatAmount(p.importoFattura)),
- _row('Totale scad.', _formatAmount(p.importoScadenza)),
- _row('Saldo', _formatAmount(p.saldo)),
- ],
- ),
- ),
- );
- },
- );
- },
- loading: () => const Center(child: CircularProgressIndicator()),
- error: (e, _) => Center(child: Text('Errore: $e')),
- );
- }
- String _formatDate(String? dateStr) {
- if (dateStr == null) return '-';
- try {
- final dt = DateTime.parse(dateStr);
- return DateFormat('dd/MM/yyyy').format(dt);
- } catch (_) {
- return dateStr;
- }
- }
- String _formatAmount(double? amount) {
- if (amount == null) return '-';
- final fmt = NumberFormat('#,##0.00', 'it');
- return '€ ${fmt.format(amount)}';
- }
- Widget _row(String label, String value) {
- return Padding(
- padding: const EdgeInsets.symmetric(vertical: 2),
- child: Row(
- children: [
- SizedBox(
- width: 110,
- child: Text(
- label,
- style: theme.textTheme.bodySmall?.copyWith(
- color: theme.colorScheme.outline,
- ),
- ),
- ),
- Expanded(
- child: Text(value, style: theme.textTheme.bodyMedium),
- ),
- ],
- ),
- );
- }
- }
|