TextEditingControllerBuilder constructor

const TextEditingControllerBuilder({
  1. Key? key,
  2. required String text,
  3. required Widget builder(
    1. BuildContext,
    2. TextEditingController
    ),
})

Exposes a TextEditingController to the child, which allows us to convert any TextField into a declarative version.

Typically used for wiring up many state fields to form inputs and making sure everything stays in sync.

If text is updated, the consuming TextField will also be updated. If the ancestor is rebuilt, the composing state will not be lost like it typically is.

TextEditingControllerBuilder(
  text: appState.name,
  builder: (context, controller) {
    return TextField(
      controller: controller,
      onChanged: (value) => appState.updateName(value),
    );
  },
);

This widget was created by Luke Pighetti and edited by GroovinChip. Please view the original source here

Implementation

const TextEditingControllerBuilder({
  super.key,
  required this.text,
  required this.builder,
});