37 lines
1 KiB
Dart
37 lines
1 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;
|
|
List<Transaction> _transactionsData = [];
|
|
|
|
List<Transaction> get transactionList {
|
|
if (_selectedCategory == null) {
|
|
return _transactionsData;
|
|
}
|
|
return _transactionsData
|
|
.where((transaction) =>
|
|
transaction.category.name == _selectedCategory?.toLowerCase())
|
|
.toList();
|
|
}
|
|
|
|
void setTransactionsList(List<Transaction> transactions) {
|
|
_transactionsData = transactions;
|
|
notifyListeners();
|
|
}
|
|
|
|
String? get selectedCategory => _selectedCategory;
|
|
|
|
void setSelectedCategory(String? category) {
|
|
_selectedCategory = category;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<List<Transaction>> loadTransactions() async {
|
|
return (await TransactionRepository.loadTransactions() as List)
|
|
.map((i) => Transaction.fromJson(i))
|
|
.toList();
|
|
}
|
|
}
|