Social Logins
How to add support for additional Providers like Facebook?
The Good thing about the library is it is written as a framework so you could easily add support for your provider of choice.
For example, Google Auth (provided inbuilt) was implemented as follows.
Comments explain all of how it happens.
/**
* Extend AuthMethod to create a new method
*/
class Google extends AuthMethod {
/**
* Provide the look and feel of the Provider Button
*/
@override
Widget getLayout(bool isInSignIn, BuildContext context) {
return Padding(
padding: const EdgeInsets.all(0),
child: NiceButton(
elevation: 8.0,
onPressed: () {
/**
* Kick off the signing Process
*/
startSigning(context);
},
text: "Google",
width: double.infinity,
radius: 40,
fontSize: 16,
background: Color(0xffc4302b),
));
}
/**
* Perform the siging process
*/
@override
Future<void> sign(bool isInSignIn, FirebaseAuth auth) async {
final GoogleSignInAccount googleUser = await GoogleSignIn().signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final GoogleAuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
return await FirebaseAuth.instance.signInWithCredential(credential);
}
}
Now pass it as a list item to SignIn Widget auth param.
final widget = SignIn(
themeColor: Colors.deepPurple,
// Sign in and Sign Up fields are customizable in EmailConfig
methods: [Google()],
auth: FirebaseAuth.instance,
onSuccess: (user, context, fields) {
showSnackBar(
'You made the signUp flow in record time. Cheers.', context);
print('user: $user \n fields: $fields');
},
);
One request in case you added support for some provider eg. Facebook please make a pull request to the repo with the code which will serve as an example. Fellow Developers will thank you!!!
Last updated
Was this helpful?