Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1851] fixed the label of textfield in form when its label position to start #1854

Merged
merged 4 commits into from
Feb 3, 2025

Conversation

TheNoumanDev
Copy link
Member

Ticket: #1851

Fixed an issue where form labels weren't updating their visibility state when the associated input field's visibility was toggled. While input fields correctly handled visibility changes, it was because the labels added separately in the form layout weren't being rebuilt again.

Changes made:

  • Added ValueListenableBuilder in form's buildGrid method to rebuild the grid layout when properties change
  • Added a formStateNotifier in FormController to track form state changes
  • Implemented property change listener in TextInputState to notify form of any controller property updates
  • Added mounted check before accessing context to prevent unmounted widget errors

Previously, changing an input field's visibility only affected the input itself, leaving its label in an inconsistent state. Now, the entire form grid rebuilds whenever any property changes, ensuring labels and inputs stay in sync.

Test EDL:

View:
  styles:
    useSafeArea: true
    backgroundColor: white

  header:
    titleText: Home
  body:
    Column:
      styles:
        padding: 24
        gap: 32
      children:
        - Button:
            label: Test
            onTap: |
              testInputA.visible = true;
              testInputB.visible = true;
        - Button:
            label: Test
            onTap: |
              testInputA.visible = false;
              testInputB.visible = false;
        - TextInput:
            label: I was invisible
            visible: false
            id: testInputA
        - Spacer:
            styles:
              size: 40
        - Form:
            styles:
              labelPosition: start
            children:
              - TextInput:
                  label: I was invisible
                  visible: false
                  id: testInputB

Bug:
Bug image
Fixed:
Fixed image


return hasAtLeastOneLabel ? Column(children: rows) : buildColumn(formItems);
return ValueListenableBuilder(
valueListenable: widget._controller.formStateNotifier,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the only change here is the ValueListenableBuilder(
valueListenable: widget._controller.formStateNotifier,

rest is the same right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, rest is same, its just change bcz of indent.

@TheNoumanDev TheNoumanDev merged commit ae34b81 into main Feb 3, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants