david-legend / otp_textfield

BSD 3-Clause "New" or "Revised" License
63 stars 40 forks source link

handleControllers not called when styles added #15

Open kn-karthik-nayak opened 1 year ago

kn-karthik-nayak commented 1 year ago

handleControllers method is called during building of textfields and it is called inside the loop, as you can see in the code (flutter_otp_text_field version 1.1.1). This still works, however, I don't understand why you are calling it inside the loop. This however results in the following behaviour.

styles added: handleControllers not called. styles not added: handleControllers called.

Expected behaviour: handleControllers should be called irrespective of whether styles added.

  Widget generateTextFields(BuildContext context) {
    List<Widget> textFields = List.generate(widget.numberOfFields, (int i) {
      addFocusNodeToEachTextField(index: i);
      addTextEditingControllerToEachTextField(index: i);

      if (widget.styles.length > 0) {
        return _buildTextField(
          context: context,
          index: i,
          style: widget.styles[i],
        );
      }
      if (widget.handleControllers != null) {
        widget.handleControllers!(_textControllers);
      }
      return _buildTextField(context: context, index: i);
    });

    return Row(
      mainAxisAlignment: widget.mainAxisAlignment,
      crossAxisAlignment: widget.crossAxisAlignment,
      children: textFields,
    );
  }