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

Usage with TextField #8

@jaripekkala

Description

@jaripekkala

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,
    ),
  ),
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions