import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:helpers/helpers/print.dart'; import 'package:rluv/global/api.dart'; import 'package:rluv/models/budget.dart'; import 'package:rluv/models/budget_category_model.dart'; import '../models/family_model.dart'; import '../models/transaction_model.dart'; import '../models/user.dart'; class Store { static final Store _instance = Store._internal(); bool _initDone = false; factory Store() { if (_instance._initDone) { return _instance; } _instance._initDone = true; _instance.dashboardProvider = FutureProvider?>( (ref) async { final family = await ref.watch(_instance.familyProvider.future); return Api().get("dashboard/${family.id}"); }, ); _instance.budgetCategoriesProvider = FutureProvider>((ref) async { final dash = await ref.watch(_instance.dashboardProvider.future); printAmber(dash); if (dash == null) return []; final categories = dash['budget_categories'] as List; return categories .map( (e) => BudgetCategory.fromJson(e as Map), ) .toList(); }); _instance.transactionsProvider = FutureProvider>((ref) async { final dash = await ref.watch(_instance.dashboardProvider.future); if (dash == null) return []; final transactions = dash['transactions'] as List; return transactions .map( (e) => Transaction.fromJson(e as Map), ) .toList(); }); return _instance; } Store._internal(); final FutureProvider userProvider = FutureProvider( (ref) { return User( id: 0, budgetId: 1, createdAt: DateTime.now(), familyId: 1, lastActivityAt: DateTime.now(), name: 'TEMP', updatedAt: DateTime.now(), ); }, ); final FutureProvider familyProvider = FutureProvider((ref) => FamilyModel( id: 1, budgetId: 1, createdAt: DateTime.now(), updatedAt: DateTime.now())); late final FutureProvider> budgetCategoriesProvider; late final FutureProvider budgetProvider; late final FutureProvider> transactionsProvider; late final FutureProvider?> dashboardProvider; void fetchDashboard() {} }