Flutter how to use form with tabview

1,012

I have the same need as you and I'm trying to manage the different forms with a Provider that has a List <GlobalKey <FormState>> formKeys = [GlobalKey <FormState> (), GlobalKey <FormState> () ...]; a key for each form. Then in a button on the tabbar onPressed: form.validate (formKey) for each form. If all forms are fine, save info, else error message.

Share:
1,012
kei nagae
Author by

kei nagae

A Software Developer who uses this site almost 1000 times a day

Updated on December 25, 2022

Comments

  • kei nagae
    kei nagae over 1 year

    I am trying to create a form with multiple tabs but for some reason if i call validate or save on form i can get only values from tab that is active and same is true for error i think it may be because form only gets values from fields that are currently rendered on screen.

    so can some one tell me how can i make form work with multiple tab-view so that after changing tab i can validate tabs that have't been visited and also from vested ones as well.

    there is AutomaticKeepAliveClientMixin but it can only keep state alive but i am more interested in onSave or validator as i am managing state in parent element not in tabviews

    Thanks in advance

  • kei nagae
    kei nagae over 3 years
    well it could be done as well and in my work I had around 20 form and each form had around 20 25 fields and for first what i did was to use form as parent of tabview and pass all editing controllers to each separate tab and on save i will make validations and was saving all errors in errors map and then was using filed decoration to show errors
  • kei nagae
    kei nagae over 3 years
    but then a found an other way that actually using pageview and for tabing i used tabbar and there is a package that can build all pages at once and then we can use form with out any issue and i am using this for the time being
  • Admin
    Admin over 3 years
    can you share some code? An example with 2 tabs?
  • kei nagae
    kei nagae over 3 years
    ok then i am writing a new answer bellow with example
  • kei nagae
    kei nagae over 3 years
    It done have a look and feel free to ask any quetions