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