Page recreate when keyboard is open on showDialog

Viewed 340

I have a problem with my flutter project, I create button to display dialog with form and textfield, when dialog is open then I tap texfield, page is recreate, this is my code

void _showDialog(){
    showDialog(
      context: context,
      builder: (BuildContext context) {

        return CupertinoAlertDialog(
          title: Text('Add New'),
          content: Card(
            color: Colors.transparent,
            elevation: 0.0,
            child: Column(
            children: <Widget>[
              TextField(
                decoration: InputDecoration(
                labelText: "Item",
                filled: true,
                fillColor: Colors.grey.shade50),
              ),
            ],
          ),
        ),
      );

      },
    );
  }

how I can solve it? thank you so much for your help

2 Answers

Mmm, from your code nothing looks weird... maybe you should share the entire class, or your business logic from another part of the tree (like a stream that rebuilds your view )... I did a basic test in the Simulator and works fine.

But now I figure you are using a StatefulWidget, cause you have access to the context, so many some other code is doing setState().

Opening or closing the keyboard by pressing on a TextField rebuilds the Scaffold or whichever material is used to wrap your screen. This is normal behavior.

By 'recreating the page' do you mean that it loses its state? (it loses the values for data like if you use hot-restart instead of hot-reload), if so then this is not the standard behavior and we may need more information on your page/code to figure this out.

Related