| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import 'package:flutter/material.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import '../../../database/daos/promozioni_dao.dart';
- import '../../../providers/database_provider.dart';
- import '../../../database/database.dart';
- import '../../widgets/empty_state.dart';
- class PromotionListPage extends ConsumerWidget {
- const PromotionListPage({super.key});
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- final promoDao = ref.read(promozioniDaoProvider);
- final promosAsync = promoDao.getActivePromos(DateTime.now().toIso8601String());
- final theme = Theme.of(context);
- return Scaffold(
- appBar: AppBar(title: const Text('Promozioni')),
- body: FutureBuilder(
- future: promosAsync,
- builder: (_, snap) {
- if (!snap.hasData) return const Center(child: CircularProgressIndicator());
- final promos = snap.data!;
- if (promos.isEmpty) return const EmptyState(icon: Icons.local_offer_outlined, title: 'Nessuna promozione attiva');
- return ListView.builder(
- itemCount: promos.length,
- itemBuilder: (_, i) => _PromoCard(promo: promos[i], promoDao: promoDao, theme: theme),
- );
- },
- ),
- );
- }
- }
- class _PromoCard extends StatelessWidget {
- final Promozione promo;
- final PromozioniDao promoDao;
- final ThemeData theme;
- const _PromoCard({required this.promo, required this.promoDao, required this.theme});
- @override
- Widget build(BuildContext context) {
- final tipoLabel = switch (promo.tipoPromozione) {
- 2 => 'Articolo Omaggio',
- 3 => 'Listino Omaggio',
- 4 => 'Omaggio a Scelta',
- 5 => 'Omaggio Automatico',
- 6 => 'Omaggio per Importo',
- 9 => 'Sconto Quantità',
- _ => 'Tipo ${promo.tipoPromozione}',
- };
- return Card(
- margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
- child: ExpansionTile(
- leading: Icon(Icons.local_offer, color: theme.colorScheme.primary),
- title: Text(promo.descrizione ?? 'Promozione'),
- subtitle: Text(tipoLabel, style: theme.textTheme.bodySmall),
- children: [
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _detail('Priorità', promo.priorita.toString()),
- if (promo.limiteQta != null) _detail('Limite Qtà', promo.limiteQta.toString()),
- if (promo.quantitaOmaggio != null) _detail('Qtà Omaggio', promo.quantitaOmaggio.toString()),
- if (promo.limiteImporto != null) _detail('Limite Importo', promo.limiteImporto.toString()),
- if (promo.dataInizio != null) _detail('Da', promo.dataInizio!),
- if (promo.dataFine != null) _detail('A', promo.dataFine!),
- ],
- ),
- ),
- ],
- ),
- );
- }
- Widget _detail(String label, String value) {
- return Padding(
- padding: const EdgeInsets.symmetric(vertical: 2),
- child: Row(
- children: [
- SizedBox(width: 120, child: Text(label, style: theme.textTheme.bodySmall?.copyWith(color: theme.colorScheme.outline))),
- Text(value),
- ],
- ),
- );
- }
- }
|