In Flutter, you can retrieve the value of an object’s property using the .
operator.
String name = person.name;
If the object is null
, attempting to access a property on it will throw a NoSuchMethodError
. You can prevent this by first checking if the object is null
before trying to access its properties.
if (person != null) {String name = person.name;}
You can also use the ?.
operator to safely access the property of an object. This operator will return null
if the object is null
, rather than throwing an error.
String name = person?.name;
If you want to retrieve the value of a property on an object that may be null
, using the ?.
operator is a good way to do it safely.
If object is Map type then you can get value by key value pair using []. instead of ’.’ operator.
for example
String name = persion['name'];
You can also use the ?.
operator to safely access the property of an object. This operator will return null
if the object is null
, rather than throwing an error.
for example:
String? name = persion?['name'];
LESSONS
COURSES
TUTORS
Quick Links
Legal Stuff
Social Media