title: Flutter - Validating User Input
body: <p>So I'm trying to create a sign up page for my app in flutter. So far, I've got some welcome text and an input form where users can input their email. I've also got a button which will eventually change the page underneath the input field that says 'next'. The idea is to have the button disabled which was simple enough to do (just added OnPressed: null) however when the user enters at least one character, followed by an '@' and then a string list of '.com,.co.uk e.t.c) the next button will become enabled. I have tried to add a validate if else statement to the form but to no joy so have removed it from the code below. I guess what I'm asking is how do I:</p>
  <ul>
  <li>Validate the input meets my requirements</li>
  <li>Disable the button if it does not</li>
  <li>Enable the button if it does</li>
  </ul>
  <p>All responses / contributions to any of the above are greatly appreciated!</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:flutter/rendering.dart';
  
  void main() {
    runApp(MyApp());
  }
  
  class MyCustomForm extends StatefulWidget {
    @override
    MyCustomFormState createState() {
      return MyCustomFormState();
    }
  }
  
  class MyCustomFormState extends State&lt;MyCustomForm&gt; {
    final _formKey = GlobalKey&lt;FormState&gt;();
  
    @override
    Widget build(BuildContext context) {
      return Form(
        key: _formKey,
        child: Column(children: &lt;Widget&gt;[
          TextFormField(
            decoration: InputDecoration(labelText: 'Enter your email'),
          ),
        ]),
      );
    }
  }
  
  class MyApp extends StatelessWidget {
    // This widget is the root of your application.
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Test Bench',
        home: Stack(
          children: [
            Scaffold(
              body: Container(
                width: double.infinity,
                decoration: BoxDecoration(color: Colors.pinkAccent),
                child: Padding(
                  padding: const EdgeInsets.all(30.0),
                  child: Column(
                    children: [
                      Text(
                        &quot;Hello, Let's Get Started...\n&quot;,
                        style: TextStyle(
                          fontSize: 60.0,
                          fontWeight: FontWeight.bold,
                          fontFamily: 'Oswald',
                          color: Colors.black,
                        ),
                      ),
                      MyCustomForm(),
                      ButtonTheme(
                        minWidth: 250.0,
                        child: RaisedButton(
                          onPressed: null,
                          child: Text(&quot;Next&quot;),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ],
        ),
      );
    }
  }
  </code></pre>