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