Add unique name check to entry form.
This commit is contained in:
parent
ef58a06dfa
commit
f5635d6120
@ -1,6 +1,4 @@
|
||||
// Flutter
|
||||
import 'dart:nativewrappers/_internal/vm/lib/ffi_allocation_patch.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_expense_tracker/db.dart';
|
||||
|
||||
@ -236,7 +234,15 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
|
||||
? Text("New Expense")
|
||||
: Text("Edit Expense"),
|
||||
),
|
||||
content: Form(
|
||||
content: FutureBuilder<List<Expense>>(
|
||||
future: DatabaseHelper.instance.getExpenses(),
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot<List<Expense>> snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return Center(child: Text('Loading...'));
|
||||
}
|
||||
List<Expense> expenses = snapshot.data!;
|
||||
return Form(
|
||||
key: _expenseFormKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@ -255,12 +261,10 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
|
||||
if (value!.isEmpty) {
|
||||
return "Name must be provided.";
|
||||
}
|
||||
// TODO: Figure out how to check the DB if a name already exists.
|
||||
/*
|
||||
if (DatabaseHelper.instance.checkExpenseNameExists(value)) {
|
||||
if (!expenses
|
||||
.every((expense) => expense.name != value)) {
|
||||
return "Name must be unique, already in use.";
|
||||
}
|
||||
*/
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) {
|
||||
@ -268,7 +272,8 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
keyboardType: TextInputType.numberWithOptions(decimal: true),
|
||||
keyboardType:
|
||||
TextInputType.numberWithOptions(decimal: true),
|
||||
decoration: InputDecoration(
|
||||
labelText: "Cost",
|
||||
hintText: "Example: 10.00",
|
||||
@ -340,7 +345,8 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
decoration: InputDecoration(
|
||||
labelText: "Description",
|
||||
hintText: "Example: 1GB data with unlimited talk & text.",
|
||||
hintText:
|
||||
"Example: 1GB data with unlimited talk & text.",
|
||||
hintStyle: TextStyle(fontSize: 8.0),
|
||||
errorStyle: TextStyle(fontSize: 10.0),
|
||||
),
|
||||
@ -354,7 +360,8 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
actions: [
|
||||
Center(
|
||||
child: ElevatedButton.icon(
|
||||
|
Loading…
x
Reference in New Issue
Block a user