Multiple entity-bound CupertinoTextFields that save on focus out

Issue

I have a list of some entries I want edit on focus out. I createe FocusNode for each entry, CupertinoTextField for each entry too.

var textField = (UserMotivator um) {
    var controller;
    var focusNode = new FocusNode();
    focusNode.addListener(() {
        if (!focusNode.hasFocus) {
            post(um);
        }
    });

    var controller = TextEditingController(text: um.text);

    return CupertinoTextField(
        focusNode: focusNode,
        controller: controller,
        onChanged: (String value) {
            um.text = value;
        }
    );
};

For some weird reason, in simulator (not tested on real device), when I click on many of these TextFields, I get this:

enter image description here

How do I bound a focus out even to a TextField without using FocusNode/ without having all of these cursors blinking?

Solution

So I resolved the issue I think. The reason it was buggy was that I was on v1.1.8, after updating to v1.5.4 it somehow got fixed, was not perfect but was better. After I moved the FocusNodes creation code form build to initState method it got even better but the cursor was still blinking at the start of the TextField. This was because I had called setState in the onChange handler, which somehow caused the TextField to redraw and act so weirdly.

Answered By – Martin.

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *