dashboard_provider.dart 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import 'package:flutter_riverpod/flutter_riverpod.dart';
  2. import '../database/database.dart';
  3. import 'database_provider.dart';
  4. class DashboardData {
  5. final List<TopCustomerData> topCustomers;
  6. final List<TopItemData> topItems;
  7. final int newOrdersCount;
  8. final int ordersOnHoldCount;
  9. final int newCustomersCount;
  10. DashboardData({
  11. this.topCustomers = const [],
  12. this.topItems = const [],
  13. this.newOrdersCount = 0,
  14. this.ordersOnHoldCount = 0,
  15. this.newCustomersCount = 0,
  16. });
  17. }
  18. final dashboardProvider =
  19. FutureProvider.family<DashboardData, int>((ref, idAgente) async {
  20. final clientiDao = ref.read(clientiDaoProvider);
  21. final articoliDao = ref.read(articoliDaoProvider);
  22. final ordiniDao = ref.read(ordiniDaoProvider);
  23. final topCusts = await clientiDao.topCustomers(5);
  24. final topItems = await articoliDao.getMostSoldItems(5);
  25. final newOrdC = await ordiniDao.countNewOrders();
  26. final ordHold = await ordiniDao.countOrdersOnHold();
  27. final newCust = await clientiDao.countNewCustomers();
  28. return DashboardData(
  29. topCustomers: topCusts,
  30. topItems: topItems,
  31. newOrdersCount: newOrdC,
  32. ordersOnHoldCount: ordHold,
  33. newCustomersCount: newCust,
  34. );
  35. });