3

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?
Christian
  • 834
  • 7
  • 18

1 Answers1

2

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.

Bashar
  • 215
  • 1
  • 9
  • I am using riverpod too. Can you elaborate on how you save the state? – Christian Sep 04 '22 at 19:36
  • You Need To Create A FormKey For Each Form And Save it In the State Part Of RiverPod This Key Holds The State Of The Form And You Can Validate Each Key To make Sure Everything is Valid – Bashar Sep 04 '22 at 20:04
  • So You need To Create 3 Keys And Assign Them To The Forms Then Work With All 3 Instead OF 1 – Bashar Sep 04 '22 at 20:04
  • does it work even if the page havent been loaded yet? – Jolzal Dec 13 '22 at 12:57