-1

I want to recreate automatically my page and clear all my TextFields on button press.Is there a method to do it?

  • You can go over the link below and re-ask your question @SiegfriedMabantey https://stackoverflow.com/help/how-to-ask – void May 16 '20 at 11:08
  • Paste your code! We can see where to fix by using best practises of flutter. The Android implementation is different from Flutter that it store the Intent for the activity and then calls the startActivity by itself so that does not exist in Flutter by advice you paste your code its easy to fix but if you want to force it anyway go here https://stackoverflow.com/questions/50115311/flutter-how-to-force-an-application-restart-in-production-mode – Xenolion May 16 '20 at 11:13

2 Answers2

1

I think it's

setState((){
  // If there is anything you want to change put it here
 });

This will rebuild the widget.

1

Edited :

Here is an example of how to achieve this :

class _MyWidgetState extends State<MyWidget> {
  final myAController = TextEditingController();
  final myBController = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          children: <Widget>[
            FlatButton(
              onPressed: () {
                setState(() {
                  myAController.clear();
                  myBController.clear();
                });
              },
              child: Text(
                "Clear text fields",
              ),
            ),
            TextField(
              controller: myAController,
              decoration: InputDecoration(
                  border: InputBorder.none, hintText: 'Enter value A'),
            ),
            TextField(
              controller: myBController,
              decoration: InputDecoration(
                  border: InputBorder.none, hintText: 'Enter Value B'),
            ),
          ],
        ),
      ),
    );
  }
}

As you can see every time i press my flatbutton the widget reloads with the updated counter value.

Here is an updated working demo.

Firas BENMBAREK
  • 306
  • 1
  • 10