skip to Main Content

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

enter image description here

2

Answers


  1. 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.

    Login or Signup to reply.
  2. you can use whenComplete() to clear your TextEditingControllers, Here is an example:

    Navigator.of(context).push(
      MaterialPageRoute(builder: (context) => YourPage()),
    ).whenComplete(() {
      customAmountController.clear();
      messageController.clear();
    });
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search