import 'package:flutter/foundation.dart'; import 'package:robo_advisory/models/transaction.dart'; import 'package:robo_advisory/repository/transaction.repository.dart'; class TransactionProvider with ChangeNotifier { String? _selectedCategory; List _transactionsData = []; List get transactionList { if (_selectedCategory == null) { return _transactionsData; } return _transactionsData .where((transaction) => transaction.category.name == _selectedCategory?.toLowerCase()) .toList(); } void setTransactionsList(List transactions) { _transactionsData = transactions; notifyListeners(); } String? get selectedCategory => _selectedCategory; void setSelectedCategory(String? category) { _selectedCategory = category; notifyListeners(); } Future> loadTransactions() async { return (await TransactionRepository.loadTransactions() as List) .map((i) => Transaction.fromJson(i)) .toList(); } }