title: Disable AlertDialog button on value change of TextFormField Flutter
body: <p>In My <strong>First</strong> Flutter Project, I am trying to get value from <strong>TextFormField</strong> inside a <strong>Alert Dialog</strong>. I am trying to validate inputs and based on that validation I want to enable/disable button of <strong>AlertDialog</strong>.</p>
  <h2>What I have done to display dialog:</h2>
  <pre><code> _displayDialog(BuildContext context) async {
      return showDialog(
          context: context,
          builder: (context) {
            return AlertDialog(
              title: Text('TextField AlertDemo'),
              content: _container(),
              actions: &lt;Widget&gt;[
                RaisedButton(
                  onPressed: isValid
                      ? () {
                          print(&quot;ISVALID:&quot;);
                        }
                      : null,
                  child: Text(&quot;Click Me&quot;),
                )
              ],
            );
          });
    }
  </code></pre>
  <h2>_container() method code:</h2>
  <pre><code> Widget _container() {
      return Container(
        margin: EdgeInsets.all(25),
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              TextFormField(
                onChanged: (text) {
                  setState(() {
                    if (text.length &gt; 5) {
                      isValid = true;
                    } else {
                      isValid = false;
                    }
                  });
                },
                decoration: InputDecoration(labelText: 'Enter Text'),
              ),
              SizedBox(height: 15),
              RaisedButton(
                onPressed: isValid
                    ? () {
                        print(&quot;ISVALID:&quot;);
                      }
                    : null,
                child: Text(&quot;Done!&quot;),
              )
            ],
          ),
        ),
      );
    }
  </code></pre>
  <p>Unfortunately It is working in <strong>body of Scaffold:</strong></p>
  <pre><code>@override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            _container(),
            RaisedButton(
              onPressed: (){_displayDialog(context);},
              child: Text(&quot;Show Alert&quot;),
            )
          ],
        ),
      );
    }
  </code></pre>
  <p>Can anyone please help me out in this problem.
  TIA</p>