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 = "All"; List _transactionsData; List _transactionsList; List get transactionList { if (_selectedCategory != 'All') { return _transactionsList = _transactionsData .where((transaction) => transaction.category.name == _selectedCategory.toLowerCase()) .toList(); } else { return _transactionsList = _transactionsData; } } void setTransactionsList(List transactions) { _transactionsData = transactions; _transactionsList = transactions; notifyListeners(); } String get selectedCategory => _selectedCategory; void setSelectedCategory(String category) { _selectedCategory = category; print(_selectedCategory); notifyListeners(); } Future> loadTransactions() async { return (await TransactionRepository.loadTransactions() as List) .map((i) => Transaction.fromJson(i)) .toList(); } }