value.isEmpty is throwing error in when i try to compile the code

MuhammadOsamaQureshi
 TextFormField(
                        obscureText: true,
                        decoration: InputDecoration(
                          hintText: "Enter password",
                          labelText: "Password",
                        ),
                        validator: (value) {
                          if (value.isEmpty) {
                            return "Password can't be empty";
                          }
                          null;
                        },
                      ),

I am watching a tutorial of flutter and i know its too basic but seems like , I can't fix this error I tried to search it but there is no proper guide to fix can someone help me in fixing this when its working fine on tutorial but not for me , and i don't get it yet its showing The property 'isEmpty' can't be unconditionally accessed because the receiver can be 'null'. Try making the access conditional (using '?.') or adding a null check to the target ('!'). this error

quoci

This is because value is of type String? and can be null. In you case you have to check if value is null.

 TextFormField(
                        obscureText: true,
                        decoration: InputDecoration(
                          hintText: "Enter password",
                          labelText: "Password",
                        ),
                        validator: (String? value) {
                          if (value != null && value.isEmpty) {
                            return "Password can't be empty";
                          }
                          null;
                        },
                      ),

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error occurred when I try to compile my code

Error about operator overloading when I try to compile this code

Java is Throwing Syntax Error When I Try to Execute an SQL Query

PyCharm throwing an error when I try to use macports python

PySimpleGui throwing error when i try to login my bot

Error package org.apache.spark.sql is not a value when I try to compile a SBT in Spark- Scala

Whenever I try to compile javascript code I get a syntax error

Why is Google Cloud Functions throwing a "Invalid value for config firebase.databaseURL" error when I try to initialize a firebase app?

I get stray '#' in program error when I try to compile this program

Why do I get an error for "__CrtGetFileInformationByHandleEx " when I try to compile

I'm getting an infinite true bool error when I try to compile this C code and I don't know why

Why there is ambiguous methods error when try to compile code?

VBA Code throwing Compile Error: Expected Array

New to c++ getting an error when I try to compile

Gcc throws error when I try to compile the test folder in libburn

Git is throwing a readlink error when I try and add files to my repo

Why is Redux throwing a null error when I try to log out a user with Firebase?

I get error when i try to add value to defaultdict(str)

Why do I get "Exception; must be caught or declared to be thrown" when I try to compile my Java code?

Try throwing an error, but why?

<< Operator throwing compile error

Pygame window not responding error when i try to run a code

error when I try to activate my code navicat 12

When I try to install vscode, snapd shows error code 400

CSS syntax error in CodeSandBox when i try to write code in a brakets

When I try to compile OpenCv with inference engine enabled, I am getting an error

PHP error message when I try to check a value from database

Python:when I try to insert JSON file into Mongodb,if the json file is not valid its throwing an error.how to catch the error

typescript error "Not all code paths return a value." when i try to manipulate response and return, but direct return response works fine