1

I am working with an application where I have multiple screens having input fields. I have to create multiple global form state key to validate each screen's form.

I heard that accessive use of global keys is not recommended. Is this true then how can i deal with validating multiple screen's forms without using large number of goobal form key??

Ranjit Shrestha
  • 622
  • 6
  • 24
  • *"I have to create multiple global form state key to validate each screen's form."* - you dont have to - you can use `Form.of` instead – pskink Nov 27 '21 at 10:08
  • @pskink any code snippet or examples for this? – Ranjit Shrestha Nov 27 '21 at 11:04
  • 1
    `child: Form( child: Column( children: [ TextFormField( validator: (s) => s!.length > 5? 'too long' : null, ), Builder( builder: (context) { return ElevatedButton(onPressed: Form.of(context)!.validate, child: Text('validate')); } ), ] ) ), ` – pskink Nov 27 '21 at 11:06

1 Answers1

0

A good method is to make your screens that contain validation StateFullWidget and define your formKey inside widget state;

reza
  • 1,354
  • 1
  • 7
  • 25