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(
|
title: Center(
|
||||||
child: widget.entry == null
|
child: widget.entry == null
|
||||||
? Text("New ${_type!.title}")
|
? Text("New ${_type!.title}")
|
||||||
: Text("Edit Expense"),
|
: Text("Edit ${_type!.title}"),
|
||||||
),
|
),
|
||||||
content: FutureBuilder<List<Expense>>(
|
content: FutureBuilder<List<Expense>>(
|
||||||
future: DatabaseHelper.instance.getExpenses(),
|
future: DatabaseHelper.instance.getExpenses(),
|
||||||
@ -399,46 +399,47 @@ class _TrackedItemInputDialogState extends State<TrackedItemInputDialog> {
|
|||||||
_amount = double.parse(value!);
|
_amount = double.parse(value!);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
DropdownButtonFormField(
|
if (_type != ItemType.asset)
|
||||||
items: Frequency.values
|
DropdownButtonFormField(
|
||||||
.map(
|
items: Frequency.values
|
||||||
(freq) => DropdownMenuItem(
|
.map(
|
||||||
value: freq,
|
(freq) => DropdownMenuItem(
|
||||||
child: Row(
|
value: freq,
|
||||||
children: [
|
child: Row(
|
||||||
Text(
|
children: [
|
||||||
freq.title,
|
Text(
|
||||||
),
|
freq.title,
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.all(1.0),
|
|
||||||
child: Text(
|
|
||||||
" (${freq.hint})",
|
|
||||||
style: TextStyle(fontSize: 10.0),
|
|
||||||
),
|
),
|
||||||
),
|
Padding(
|
||||||
],
|
padding: EdgeInsets.all(1.0),
|
||||||
|
child: Text(
|
||||||
|
" (${freq.hint})",
|
||||||
|
style: TextStyle(fontSize: 10.0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
)
|
.toList(),
|
||||||
.toList(),
|
value: _freq,
|
||||||
value: _freq,
|
decoration: InputDecoration(
|
||||||
decoration: InputDecoration(
|
labelText: "Frequency",
|
||||||
labelText: "Frequency",
|
errorStyle: TextStyle(fontSize: 10.0),
|
||||||
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(
|
TextFormField(
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
textCapitalization: TextCapitalization.sentences,
|
textCapitalization: TextCapitalization.sentences,
|
||||||
@ -468,21 +469,64 @@ class _TrackedItemInputDialogState extends State<TrackedItemInputDialog> {
|
|||||||
if (_formKey.currentState!.validate()) {
|
if (_formKey.currentState!.validate()) {
|
||||||
_formKey.currentState!.save();
|
_formKey.currentState!.save();
|
||||||
setState(() {
|
setState(() {
|
||||||
Expense expense = Expense(
|
switch (_type) {
|
||||||
id: _id,
|
case ItemType.expense:
|
||||||
name: _name,
|
Expense expense = Expense(
|
||||||
amount: _amount,
|
id: _id,
|
||||||
frequency: _freq,
|
name: _name,
|
||||||
description: _desc,
|
amount: _amount,
|
||||||
);
|
frequency: _freq,
|
||||||
if (_id != null) {
|
description: _desc,
|
||||||
DatabaseHelper.instance.updateExpense(
|
);
|
||||||
expense,
|
if (_id != null) {
|
||||||
);
|
DatabaseHelper.instance.updateExpense(
|
||||||
} else {
|
expense,
|
||||||
DatabaseHelper.instance.addExpense(
|
);
|
||||||
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();
|
widget.notifyParent();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user