refactor: remove categoryName from TransactionRecord and use category reference
This commit is contained in:
@@ -4,7 +4,6 @@ import 'category.dart';
|
||||
class TransactionRecord {
|
||||
final int id;
|
||||
final String type; // 'income' or 'expense'
|
||||
final String categoryName;
|
||||
final double amount;
|
||||
final Category? category; // Reference to category (null for income)
|
||||
final DateTime date;
|
||||
@@ -13,9 +12,8 @@ class TransactionRecord {
|
||||
TransactionRecord({
|
||||
required this.id,
|
||||
required this.type,
|
||||
required this.categoryName,
|
||||
required this.amount,
|
||||
this.category, // Optional since income may not have a category
|
||||
this.category,
|
||||
required this.date,
|
||||
required this.merchant,
|
||||
});
|
||||
|
||||
@@ -499,14 +499,19 @@ class _ExpensesScreenState extends State<ExpensesScreen> with TickerProviderStat
|
||||
|
||||
// Create the model.TransactionRecord needed by TransactionListItem
|
||||
final transactionRecord = model.TransactionRecord(
|
||||
id: dbTransaction.id, // Pass the actual ID
|
||||
type: dbTransaction.type, // Pass the type
|
||||
categoryName: dbTransaction.categoryName, // Pass category or 'Income'
|
||||
id: dbTransaction.id,
|
||||
type: dbTransaction.type,
|
||||
amount: dbTransaction.amount,
|
||||
iconCode: categoryDetails.iconCode, // Get icon
|
||||
color: categoryDetails.colorCode, // Get color
|
||||
category: dbTransaction.type == 'expense'
|
||||
? Category(
|
||||
dbTransaction.categoryName,
|
||||
dbTransaction.amount,
|
||||
categoryDetails.colorCode,
|
||||
categoryDetails.iconCode,
|
||||
)
|
||||
: null,
|
||||
date: dbTransaction.date,
|
||||
merchant: dbTransaction.merchant, // Pass merchant or source
|
||||
merchant: dbTransaction.merchant,
|
||||
);
|
||||
|
||||
// Use the TransactionListItem widget
|
||||
|
||||
@@ -81,7 +81,7 @@ class TransactionListItem extends StatelessWidget {
|
||||
|
||||
// Title: Category Name (for expense) or "Income"
|
||||
title: Text(
|
||||
isIncome ? 'Income' : transaction.categoryName, // Show "Income" or category name
|
||||
isIncome ? 'Income' : transaction.category?.name ?? 'Uncategorized', // Show "Income" or category name
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 14.5,
|
||||
|
||||
Reference in New Issue
Block a user