i have a screen has to textformfield 1- customAmountController , 2-messageController and i fill that and go to next screen but when i pop from this screen to my form screen my 2 textformfiled should be empty so how can i do that
Your question isn’t very clear, but I am assuming you don’t want changes to persist between visits to a certain page. With code we could also determine exactly why the problem is occurring, so I will proceed to deductively propose possible problems.
Possible Problem #1:
Changes persisting are likely due to a TextEditingController being of a higher scope than your page widget. If the controller wasn’t of another scope, it would reset to its initial state every time the page loads.
You can solve this by resetting the controller in the page’s build method or by moving the controller inside the class.
Possible Problem #2:
Another likely problem is that the page isn’t being reloaded when being navigated to with a pop method. If method 1 doesn’t work, then try navigating away from this page with the following: Navigator.of(context).pushNamed("/myRoute").then((value) => setState(() {}));
Popping will definitely reload the page(if it is a stateful widget) after this.
If you provide code, I could tell you without having to guess the problem.
In this code snippet, whenComplete() is used to clear the TextEditingControllers (customAmountController and messageController) after navigating to the YourPage page. This ensures that the text fields are cleared when the user returns from the YourPage page.
2
Answers
Your question isn’t very clear, but I am assuming you don’t want changes to persist between visits to a certain page. With code we could also determine exactly why the problem is occurring, so I will proceed to deductively propose possible problems.
Possible Problem #1:
Changes persisting are likely due to a
TextEditingController
being of a higher scope than your page widget. If the controller wasn’t of another scope, it would reset to its initial state every time the page loads.You can solve this by resetting the controller in the page’s build method or by moving the controller inside the class.
Possible Problem #2:
Another likely problem is that the page isn’t being reloaded when being navigated to with a pop method. If method 1 doesn’t work, then try navigating away from this page with the following:
Navigator.of(context).pushNamed("/myRoute").then((value) => setState(() {}));
Popping will definitely reload the page(if it is a stateful widget) after this.
If you provide code, I could tell you without having to guess the problem.
you can use
whenComplete()
to clear yourTextEditingControllers
, Here is an example:In this code snippet,
whenComplete()
is used to clear theTextEditingControllers
(customAmountController
andmessageController
) after navigating to theYourPage
page. This ensures that the text fields are cleared when the user returns from theYourPage
page.