added validation to name field of add pizza event page

This commit is contained in:
broodjeaap89 2021-07-09 17:32:42 +02:00
parent 898aba7dbf
commit 73ea84ec69

View file

@ -19,6 +19,9 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
int pizzaCount = 1; int pizzaCount = 1;
int doughBallSize = 250; int doughBallSize = 250;
DateTime eventTime = DateTime.now(); DateTime eventTime = DateTime.now();
bool nameValidation = false;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -36,7 +39,8 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
Expanded( Expanded(
child: TextField( child: TextField(
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Event Name" hintText: "Event Name",
errorText: this.nameValidation ? "Name can\'t be empty" : null
), ),
onChanged: (String newName) { onChanged: (String newName) {
setState(() { setState(() {
@ -143,6 +147,10 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
child: TextButton( child: TextButton(
child: Text("Add", style: TextStyle(color: Colors.white)), child: Text("Add", style: TextStyle(color: Colors.white)),
onPressed: () { onPressed: () {
if (this.name.length == 0){
setState(() { this.nameValidation = true; });
return;
}
Navigator.pop(context, PizzaEvent( Navigator.pop(context, PizzaEvent(
this.name, this.name,
this.pizzaType, this.pizzaType,