Learn Pain Less

HomeOur TeamContact
Flutter
Get value from object flutter
Pawneshwer Gupta
Pawneshwer Gupta
January 03, 2023
1 min
Get value from object flutter

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'];

Learn Flutter in 90 days with Pawneshwer!

Dart Beginners Course in Hindi free of cost for limited period.

Start Learning

250+

LESSONS

30+

COURSES

15+

TUTORS

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Tags

Flutterobject

Share


Pawneshwer Gupta

Pawneshwer Gupta

Software Developer

Pawneshwer Gupta works as a software engineer who is enthusiastic in creating efficient and innovative software solutions.

Expertise

Python
Flutter
Laravel
NodeJS

Social Media

Related Posts

[Fixed] Error: Member not found: 'packageRoot' in Flutter
[Fixed] Error: Member not found: 'packageRoot' in Flutter
March 03, 2023
2 min
Learn Pain Less  © 2024, All Rights Reserved.
Crafted with by Prolong Services

Quick Links

Advertise with usAbout UsContact Us

Social Media