0
votes

I'm successfully logging into Facebook with Flutter using the flutter_facebook_auth package and now I'm having trouble getting my user profile info in the getUserData method map. Here is my code....

var userData = await FacebookAuth.instance.getUserData();
Map<String, dynamic> _userData;
_userData = userData;
var info = _userData['items'];

String facebookName;

for (var items in info) {
  Map myMap = items; //store each map
  var name = (myMap['name'] as Map).toString();
  facebookName = name;
}

When trying to print facebookName, I get the following error...

The getter 'iterator' was called on null.

I'm not sure exactly where I'm getting this wrong. Please help!

Printing _userData give the following desired map...

flutter: {email: , id: , picture: {data: {is_silhouette: false, height: 122, url: , width: 200}}, name: Charles Cleveland Jr.}

1
Can you log your _userData variable ? - dm_tr
The info variable is null - Charles Jr
_userData is the correct map with my name, email, and an imbedded data map for user pictures - Charles Jr
Post it's content boss - dm_tr
If there are sensitive data you can change them to fake ones - dm_tr

1 Answers

1
votes

If you want to get the name, you can proceed as following

String facebookName;
_userData.forEach((key, value) {
  if ("name" == key) facebookName = value;
});
print(facebookName);