title: The property 'isEmpty" can't be unconditionally accessed because the receiver can be 'null'
body: <pre class="lang-dart prettyprint-override"><code>import 'package:flutter/material.dart';
      import 'package:flutter_app_1/utils/routes.dart';
      
      class LoginPage extends StatefulWidget {
        @override
        _LoginPageState createState() =&gt; _LoginPageState();
      }
      
      class _LoginPageState extends State&lt;LoginPage&gt; {
        String name = &quot;&quot;;
        bool changeButton = false;
      
        final _formKey = GlobalKey&lt;FormState&gt;();
      
        moveToHome(BuildContext context) async {
          if (_formKey.currentState.validate()) {
            setState(() {
              changeButton = true;
            });
            await Future.delayed(Duration(seconds: 1));
            await Navigator.pushNamed(context, MyRoutes.homeRoute);
            setState(() {
              changeButton = false;
            });
          }
        }
      
        @override
        Widget build(BuildContext context) {
          return Material(
              color: Colors.white,
              child: SingleChildScrollView(
                child: Form(
                  key: _formKey,
                  child: Column(
                    children: [
                      Image.asset(
                        &quot;assets/images/login_image.png&quot;,
                        fit: BoxFit.cover,
                        height: 500,
                      ),
                      SizedBox(
                        height: 20.0,
                      ),
                      Text(
                        &quot;Welcome $name&quot;,
                        style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
                      ),
                      SizedBox(
                        height: 28.0,
                      ),
                      Padding(
                        padding: const EdgeInsets.symmetric(
                            vertical: 16.0, horizontal: 32.0),
                        child: Column(
                          children: [
                            TextFormField(
                              decoration: InputDecoration(
                                hintText: &quot;Enter User Name&quot;,
                                labelText: &quot;Username&quot;,
                              ),
                              validator: (String? value) {
                                if (value != null &amp;&amp; value.isEmpty) {
                                  return &quot;Username can't be empty&quot;;
                                }
      
                                return null;
                              },
                              onChanged: (value) {
                                name = value;
                                setState(() {});
                              },
                            ),
                            TextFormField(
                              obscureText: true,
                              decoration: InputDecoration(
                                hintText: &quot;Enter password&quot;,
                                labelText: &quot;Password&quot;,
                              ),
                              validator: (String? value) {
                                if (value != null &amp;&amp; value.isEmpty) {
                                  return &quot;Password can't be empty&quot;;
                                }
      
                                return null;
                              },
                            ),
                            SizedBox(
                              height: 40.0,
                            ),
                            Material(
                              color: Colors.deepPurple,
                              borderRadius:
                                  BorderRadius.circular(changeButton ? 50 : 8),
                              child: InkWell(
                                onTap: () =&gt; moveToHome(context),
                                child: AnimatedContainer(
                                  duration: Duration(seconds: 1),
                                  width: changeButton ? 50 : 150,
                                  height: 50,
                                  //color: Colors.deepPurple,
                                  alignment: Alignment.center,
                                  child: changeButton
                                      ? Icon(
                                          Icons.done,
                                          color: Colors.white,
                                        )
                                      : Text(
                                          &quot;Login&quot;,
                                          style: TextStyle(
                                              color: Colors.white,
                                              fontWeight: FontWeight.bold,
                                              fontSize: 18),
                                        ),
                                  // decoration: BoxDecoration(
                                  //     //color: Colors.deepPurple,
                                  //     // shape: changeButton
                                  //     //     ? BoxShape.circle
                                  //     //     : BoxShape.rectangle,
                                  //     ),
                                ),
                              ),
                            ),
                            // ElevatedButton(
                            //     child: Text(&quot;Login&quot;),
                            //     style: TextButton.styleFrom(minimumSize: Size(150, 40)),
                            //     onPressed: () {
                            //       Navigator.pushNamed(context, MyRoutes.homeRoute);
                            //     })
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              ));
        }
      }
  </code></pre>
  <p>Hi All,
  I'm trying to add validator to widget but I'm getting this error please help. to solve this error.</p>
  <p>The Error:</p>
  <p><code>The method 'validate' can't be unconditionally invoked because the receiver can be 'null'. Try making the call conditional (using '?.') or adding a null check to the target ('!')</code></p>
  <p>I tried replacing the code provided and still I'm getting the error. please look into it.</p>
  <p>Second Error:</p>
  <p><code>The method 'validate' can't be unconditionally invoked because the receiver can be 'null'. Try making the call conditional (using '?.') or adding a null check to the target ('!')</code></p>
  <p>I tried replacing the code provided and still I'm getting the error. please look into it.</p>