getUserData method

  1. @override
Future<Map<String, dynamic>> getUserData({
  1. String fields = "name,email,picture.width(200)",
})

get the user profile information

fields string of fields like birthday,email,hometown

The facebook SDK will return a JSON like

{
 "name": "Open Graph Test User",
 "email": "open_jygexjs_user@tfbnw.net",
 "picture": {
   "data": {
     "height": 126,
     "is_silhouette": true,
     "url": "https://scontent.fuio21-1.fna.fbcdn.net/v/t1.30497-1/s200x200/84628273_176159830277856_972693363922829312_n.jpg",
     "width": 200
   }
 },
 "id": "136742241592917"
}

Implementation

@override
Future<Map<String, dynamic>> getUserData({
  String fields = "name,email,picture.width(200)",
}) async {
  if (!_initialized) return {"error": "window.FB is undefined"};
  Completer<Map<String, dynamic>> c = Completer();
  fb.api(
    "/me?fields=$fields",
    allowInterop(
      (_) => c.complete(
        Map<String, dynamic>.from(
          convert(_),
        ),
      ),
    ),
  );
  return c.future;
}