I want to display something in a Text whenever a TextFields text changes:
class _MyPageState extends State<MyPage> {
String name;
@override
Widget build(BuildContext context) {
TextEditingController c = new TextEditingController(text: name);
c.addListener(() {
setState(() { name = c.text;});
});
return Scaffold(
body: Center(
child: Column(children: [
Text('Hello, ' + name + '!'),
TextField(controller: c)
])));
}
}
The Text updates as exspected, but the problem is that the Cursor of the TextField moves to position 0 each time I enter a character.