1

So I'm working on a TextField with scoped_model. I moved the controller to the Model class, and I'm trying to change the state of a Text with the text the user inputs on said TextField. But when I close the keyboard, the state changes and the TextField is now empty, so nothing is seen on the Text widget either. This is my code:

CupertinoTextField(
  controller: model.lastNameController,
  onChanged: (text) => model.changeShortLastNameState(lastName: text),
),

And this is the relevant code on my Model

final lastNameController = TextEditingController();

void changeShortLastNameState({String lastName}) {
  var splitLastName = lastName.split(' ');
  var shortLastName = splitLastName[0];
  this.shortLastName = shortLastName;
  notifyListeners();
}

I found someone on the flutter github with the same issue, but they sent him to SO, and I haven't been successful on finding a question by the same guy. Does anyone know how to solve this issue? Thanks.

herrmartell
  • 3,057
  • 4
  • 18
  • 27

1 Answers1

0

Use the deceleration of text editing controller out side of build function.