Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Usage with TextField #8

Open
jaripekkala opened this issue Oct 27, 2019 · 1 comment
Open

Usage with TextField #8

jaripekkala opened this issue Oct 27, 2019 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@jaripekkala
Copy link
Member

jaripekkala commented Oct 27, 2019

Currently there aren't perfect solution for the most common form field.

TextFormField

Works. However formini state resets on hot reload and TextFormField's state doesn't causing the input show previous (mismatching with state) value.

FormControlBuilder(
  control: user.email,
  builder: (context, state) => TextFormField(
    initialValue: state.value,
    onChanged: user.email.setValue,
    decoration: InputDecoration(
      labelText: 'Email address',
      errorText: state.dirty ? state.error?.toString() : null,
    ),
  ),
)

TextField

Works. However the TextEditingController also controls the cursor state so creating a new control for every value causes the cursor to go to the beginning of the value.

FormControlBuilder(
  control: user.email,
  builder: (context, state) => TextField(
    controller: TextEditingController(text: state.value),
    onChanged: user.email.setValue,
    decoration: InputDecoration(
      labelText: 'Email address',
      errorText: state.dirty ? state.error?.toString() : null,
    ),
  ),
)

FormEditableTextAdaptor

Works pretty much perfectly once done right. However formini doesn't provide form fields and this widget got too dangerously close to that area thus deleted from the codebase.

https://github.com/vantageoy/formini/blob/21af81ba70c1eebcbdc826ef292fe323850f7b92/lib/src/flutter/adaptors/form_editable_text_adaptor.dart

FormEditableTextAdaptor(
  control: user.email,
  builder: (context, controller, state) => TextField(
    controller: controller,
    decoration: InputDecoration(
      labelText: 'Email address',
      errorText: state.dirty ? state.error?.toString() : null,
    ),
  ),
)
@jaripekkala
Copy link
Member Author

Formini state reseting on hot reload is probably something we want to fix. I still really don't like the fact the view widget (TextFormField) has a duplicate state of the field.

@jaripekkala jaripekkala added help wanted Extra attention is needed bug Something isn't working labels Oct 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant