How to fix the cursor movement with onChange event of flutter?

2,283 views
Skip to first unread message

Thunder Birds

unread,
May 7, 2021, 2:59:25 AM5/7/21
to Flutter Development (flutter-dev)

The cursor is continuously moving to front while typing data in text field. Before it is not there but once I wired onChange event, it is happening.

My issue:

ezgif-4-9c39476ab5cb.gif

My code:

Padding( padding: const EdgeInsets.all(8.0), child: TextField( controller: descriptionController, decoration: InputDecoration( labelText: 'Any Details', hintText: "e.g. Whatever details you want to save", labelStyle: textStyle, border: OutlineInputBorder( borderRadius: BorderRadius.circular(5.0) ), ), keyboardType: TextInputType.text, onChanged: (String string){ setState(() { if (string != null){ coinOrder.description = string; } }); }, ), )

Suzuki Tomohiro

unread,
May 7, 2021, 12:33:17 PM5/7/21
to Thunder Birds, Flutter Development (flutter-dev)
Usually you don’t touch onChanged when you specify controller. The controller has addListener method to detect changes.

Next time you share your code, (1) use gist.github.com and (2) include other parts if the code, especially your State definition.

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/fc9c9967-0392-4316-b8c7-8bb5d54fc6c8n%40googlegroups.com.

Thunder Birds

unread,
May 7, 2021, 1:24:54 PM5/7/21
to Suzuki Tomohiro, Flutter Development (flutter-dev)
We need to modify another text field value based on this text field and vice versa.
So kept onChanged event.
I shared the code already. 

Suzuki Tomohiro

unread,
May 7, 2021, 8:40:13 PM5/7/21
to Thunder Birds, Flutter Development (flutter-dev)
Use TextEditingController’s addListener method to detect changes. Stop using onChanged. Let me know how it goes.

Thunder Birds

unread,
May 8, 2021, 1:28:35 AM5/8/21
to Suzuki Tomohiro, Flutter Development (flutter-dev)
TextEditingController
How to implement in this case?
I have three fields.
amount,count and price. Based on the price field user entered. If user enters count field, amount should be auto populated and if the user enters amount field, then count should be populated by dividing with price value.
How you suggest to implement here?

Suzuki Tomohiro

unread,
May 8, 2021, 7:35:07 AM5/8/21
to Thunder Birds, Flutter Development (flutter-dev)
Use TextEditingController’s addListener method to detect changes, instead of onChanged.
Reply all
Reply to author
Forward
0 new messages