Income and Assets are successfully being inserted and selected! Still needs tweaking, such as Asset saying "monthly".
This commit is contained in:
parent
f6f167dd83
commit
e5e85b68ff
@ -331,7 +331,7 @@ class _TrackedItemInputDialogState extends State<TrackedItemInputDialog> {
|
||||
title: Center(
|
||||
child: widget.entry == null
|
||||
? Text("New ${_type!.title}")
|
||||
: Text("Edit Expense"),
|
||||
: Text("Edit ${_type!.title}"),
|
||||
),
|
||||
content: FutureBuilder<List<Expense>>(
|
||||
future: DatabaseHelper.instance.getExpenses(),
|
||||
@ -399,46 +399,47 @@ class _TrackedItemInputDialogState extends State<TrackedItemInputDialog> {
|
||||
_amount = double.parse(value!);
|
||||
},
|
||||
),
|
||||
DropdownButtonFormField(
|
||||
items: Frequency.values
|
||||
.map(
|
||||
(freq) => DropdownMenuItem(
|
||||
value: freq,
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
freq.title,
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(1.0),
|
||||
child: Text(
|
||||
" (${freq.hint})",
|
||||
style: TextStyle(fontSize: 10.0),
|
||||
if (_type != ItemType.asset)
|
||||
DropdownButtonFormField(
|
||||
items: Frequency.values
|
||||
.map(
|
||||
(freq) => DropdownMenuItem(
|
||||
value: freq,
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
freq.title,
|
||||
),
|
||||
),
|
||||
],
|
||||
Padding(
|
||||
padding: EdgeInsets.all(1.0),
|
||||
child: Text(
|
||||
" (${freq.hint})",
|
||||
style: TextStyle(fontSize: 10.0),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
value: _freq,
|
||||
decoration: InputDecoration(
|
||||
labelText: "Frequency",
|
||||
errorStyle: TextStyle(fontSize: 10.0),
|
||||
)
|
||||
.toList(),
|
||||
value: _freq,
|
||||
decoration: InputDecoration(
|
||||
labelText: "Frequency",
|
||||
errorStyle: TextStyle(fontSize: 10.0),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null) {
|
||||
return "Frequency must be provided.";
|
||||
}
|
||||
if (!Frequency.values.contains(value)) {
|
||||
return "Value not valid.";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onChanged: (value) {
|
||||
_freq = value!;
|
||||
},
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null) {
|
||||
return "Frequency must be provided.";
|
||||
}
|
||||
if (!Frequency.values.contains(value)) {
|
||||
return "Value not valid.";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onChanged: (value) {
|
||||
_freq = value!;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
keyboardType: TextInputType.text,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
@ -468,21 +469,64 @@ class _TrackedItemInputDialogState extends State<TrackedItemInputDialog> {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
setState(() {
|
||||
Expense expense = Expense(
|
||||
id: _id,
|
||||
name: _name,
|
||||
amount: _amount,
|
||||
frequency: _freq,
|
||||
description: _desc,
|
||||
);
|
||||
if (_id != null) {
|
||||
DatabaseHelper.instance.updateExpense(
|
||||
expense,
|
||||
);
|
||||
} else {
|
||||
DatabaseHelper.instance.addExpense(
|
||||
expense,
|
||||
);
|
||||
switch (_type) {
|
||||
case ItemType.expense:
|
||||
Expense expense = Expense(
|
||||
id: _id,
|
||||
name: _name,
|
||||
amount: _amount,
|
||||
frequency: _freq,
|
||||
description: _desc,
|
||||
);
|
||||
if (_id != null) {
|
||||
DatabaseHelper.instance.updateExpense(
|
||||
expense,
|
||||
);
|
||||
} else {
|
||||
DatabaseHelper.instance.addExpense(
|
||||
expense,
|
||||
);
|
||||
}
|
||||
break;
|
||||
case ItemType.income:
|
||||
Income income = Income(
|
||||
id: _id,
|
||||
name: _name,
|
||||
amount: _amount,
|
||||
frequency: _freq,
|
||||
description: _desc,
|
||||
);
|
||||
if (_id != null) {
|
||||
DatabaseHelper.instance.updateIncome(
|
||||
income,
|
||||
);
|
||||
} else {
|
||||
DatabaseHelper.instance.addIncome(
|
||||
income,
|
||||
);
|
||||
}
|
||||
break;
|
||||
case ItemType.asset:
|
||||
Asset asset = Asset(
|
||||
id: _id,
|
||||
name: _name,
|
||||
amount: _amount,
|
||||
description: _desc,
|
||||
);
|
||||
if (_id != null) {
|
||||
DatabaseHelper.instance.updateAsset(
|
||||
asset,
|
||||
);
|
||||
} else {
|
||||
DatabaseHelper.instance.addAsset(
|
||||
asset,
|
||||
);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw UnimplementedError(
|
||||
"No code for type ${_type!.title}",
|
||||
);
|
||||
}
|
||||
});
|
||||
widget.notifyParent();
|
||||
|
Loading…
x
Reference in New Issue
Block a user