Search code examples
fluttertextfielddirection

TextFormField enters value backwards [Flutter]


As displayed in the GIF below, the TextFormField i am using is entering the values backwards. I have set the TextDirection property to ltr as well but it did not change anything. Other TextFormFields dont seem to be having this issue. The entered text is being sent back to another screen using Navigator.pop and it is sent in the same backwards manned.

Weird TextFormField

Code for the textFormField causing the issue:

TextFormField(
// validator: (String value) {
// return value.isEmpty ? "task must have a name" : null;
// },
    textDirection: TextDirection.ltr,
    maxLength: 100,
    controller: newcontroller, // Just an ordinary TextController
    onChanged: (value) {
        setState(() {
            newcontroller.text = value;
        });
    },
    decoration: InputDecoration(
        errorText: _validate  // Just a boolean value set to false by default
                   ? 'Value Can\'t Be Empty' : null,
        labelText: "name of task"
    ),
    style: TextStyle(height: 1.2, fontSize: 20, color: Colors.black87)
)

Solution

  • you can send whatever you want in Navigator.pop(context,whtever you want to pass)

      TextFormField(
    //                        validator: (String value) {
    //                          return value.isEmpty ? "task must have a name" : null;
    //                        },
                    textAlign: TextAlign.end,
                    maxLength: 100,
                    controller: newcontroller, // Just an ordinary TextController
                    onChanged: (value) {
                      print(value);
                    },
    
                    decoration: InputDecoration(
                        errorText:
                            _validate // Just a boolean value set to false by default
                                ? 'Value Can\'t Be Empty'
                                : null,
                        labelText: "name of task"),
                    style:
                        TextStyle(height: 1.2, fontSize: 20, color: Colors.black87),
                  ),
                  MaterialButton(
                    onPressed: () {
                      Navigator.pop(context, newcontroller.text);
                    },
                    child: Text("GO BACK!"),
                  ),