From 73ea84ec696a0d22fc57bfe9b30fe990bbe77b78 Mon Sep 17 00:00:00 2001 From: broodjeaap89 Date: Fri, 9 Jul 2021 17:32:42 +0200 Subject: [PATCH] added validation to name field of add pizza event page --- lib/pages/AddPizzaEventPage.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/pages/AddPizzaEventPage.dart b/lib/pages/AddPizzaEventPage.dart index 064186a..eced963 100644 --- a/lib/pages/AddPizzaEventPage.dart +++ b/lib/pages/AddPizzaEventPage.dart @@ -19,6 +19,9 @@ class AddPizzaEventPageState extends State { int pizzaCount = 1; int doughBallSize = 250; DateTime eventTime = DateTime.now(); + + bool nameValidation = false; + @override Widget build(BuildContext context) { return Scaffold( @@ -36,7 +39,8 @@ class AddPizzaEventPageState extends State { Expanded( child: TextField( decoration: InputDecoration( - hintText: "Event Name" + hintText: "Event Name", + errorText: this.nameValidation ? "Name can\'t be empty" : null ), onChanged: (String newName) { setState(() { @@ -143,6 +147,10 @@ class AddPizzaEventPageState extends State { child: TextButton( child: Text("Add", style: TextStyle(color: Colors.white)), onPressed: () { + if (this.name.length == 0){ + setState(() { this.nameValidation = true; }); + return; + } Navigator.pop(context, PizzaEvent( this.name, this.pizzaType,