Home > Mobile >  How to show profile picture based on login with Gmail or Facebook?
How to show profile picture based on login with Gmail or Facebook?

Time:03-15

If user signup with gmail I want to show Gmail profile picture else if user signup with Facebook I want to show Facebook profile picture and if user signup by register I want to ask for image or giving a normal user dummy image.

How can I get this in flutter?

CodePudding user response:

You can use profile image from response given by Google Sign Up and Facebook Sign Up. For Normal SignUp , you can ask for profile image after signup and save it in your database.

CodePudding user response:

The easiest way to manage all those 3 methods of user login is using FlutterFire (which can be looked at https://firebase.flutter.dev/docs/auth/social how to use social auth), using Social Auth plugins you will be able to manage which way they login, then after login you can check if there is an profile image available.

Even using FlutterFire you will need some additional plugins, for Google Auth it will be google_sign_in [https://pub.dev/packages/google_sign_in] which you can grab the user profile picture (if available) after getting userData as displayed in this file: https://github.com/flutter/plugins/blob/3becd1c22c9c3ac18123421fd16b0067bf95e5b1/packages/google_sign_in/google_sign_in/lib/src/common.dart#L33-L36

For Facebook Auth, the plugin is called flutter_facebook_auth [https://pub.dev/packages/flutter_facebook_auth] and you can grab user data with profile picture as showed here(https://github.com/darwin-morocho/flutter-facebook-auth/blob/f95e99e33f0bb7d59bf0099a85d074b6dda724a9/facebook_auth/lib/flutter_facebook_auth.dart#L40-L64)

Even there, what I suggest for you is using FlutterFire UI where you will be able to manage easily all those logins and userData, check these links:

FlutterFire Authentication: https://firebase.flutter.dev/docs/auth/overview

FlutterFire UI: https://firebase.flutter.dev/docs/ui/overview

And then follow instructions from https://firebase.flutter.dev/docs/ui/auth to reach you needs managing profile picture.

  • Related