Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

isempty is showing Error under validator in Flutter

Hi I am very New in Flutter and trying to learn new stuff i am facing issue on value.isEmpty i don’t know why it is showing error in attribute validator. Please look at my code and suggest me a solution

  TextFormField(
    decoration: const InputDecoration(
      icon: const Icon(Icons.phone),
      hintText: 'Enter a phone number',
      labelText: 'Phone',
    ),
    validator: (value) {
      if (value.isEmpty) {
        return 'Please enter phone number';
      }
      return null;
    },
  ),

Image:
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

 TextFormField(
    decoration: const InputDecoration(
      icon: const Icon(Icons.phone),
      hintText: 'Enter a phone number',
      labelText: 'Phone',
    ),
    validator: (value) {
      if (value!.isEmpty) {
        return 'Please enter phone number';
      }
      return null;
    },
  ),

use value!.isEmpty instead of value.isEmpty.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading