Home > Enterprise >  How to validate TextFormFields, that are at different pages inside a PageView
How to validate TextFormFields, that are at different pages inside a PageView

Time:09-05

So lets say I have 3 Pages : [StartingPage, NamePage, AdressPage] inside a PageView.

Each of those children has a TextFormField inside it.

When I am at StartingPage I want to call .validate() on the keys of the TextFormFields on NamePage and AdressPage and I want the errorLabels to show, when the user navigates to the other pages. The problem is that currently, the validation only works for the TextFormFields that are on screen.

So basically there are two questions:

  1. Is it possible to pre-build pages of a pageview? Otherwise when I call formFieldKey.currentState the state is null if I haven't navigated to the respective page.
  2. Is there another way to validate offscreen TextFormField content and show the errorlabel, when they come into view?

CodePudding user response:

Unfortunately Flutter Dosen't Support Multi-Page Forms So You Need To Implement Advanced State Management To Make This Happen. I Used Riverpod To Create a 4 Page Form By Creating A Form Key For Every Page And Saving The State of the Forms, This Way Every Form Will keep Its State Until You Dispose Of it, Hope This Helped.

  • Related