'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.

  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;
    },
  ),

enter image description here



Solution 1:[1]

Try this:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 My Car