signInWithFacebook method
Implementation
Future signInWithFacebook(BuildContext context,
{Widget? page,Position? position}) async {
await plugin.logOut();
await plugin.logIn(permissions: [
FacebookPermission.publicProfile,
FacebookPermission.email,
]);
final token = await plugin.accessToken;
FacebookUserProfile? profile;
String? email;
String imageUrl;
if (token != null) {
profile = await plugin.getUserProfile();
if (token.permissions.contains(FacebookPermission.email.name)) {
email = await plugin.getUserEmail();
if (email == '') {
// email = Helper().createEmail();
}
Preferences.getFirebase().then((token) {
ApiSellon.createDefaultParams((parameter) {
parameter.set("email", email!);
parameter.set("fcm_token", token!);
parameter.set("device", Platform.isIOS ? "ios" : "android");
parameter.set("fb_id", profile!.userId);
if (position != null){
parameter.set("latitude", position.latitude);
parameter.set("longtitude", position.longitude);
}
// parameter.set("coverage_id", cover!.id );
// if (cover.jalan != null) {
// // print("cover .")
// parameter.set("address_longitude", cover.long );
// parameter.set("address_latitude", cover.lat );
// parameter.set("address_kodepos", cover.posCode );
// parameter.set("address_kelurahan", cover.kelurahan );
// parameter.set("address_kecamatan", cover.kecamatan );
// parameter.set("address_kabkota", cover.kota );
// parameter.set("address_provinsi", cover.provinsi );
// parameter.set("address_alamat2", cover.jalan );
// parameter.set("country_origin", cover.negara );
// }
apiLoginMediaSosial(context, parameter, RegisterWith.facebookSign,
profile.userId, email, profile.name!,
page: page);
// Helper().apiLoginMediaSosial(context,parameter).then((value) {
// // isLoading = false;
// // setState(() {
// //
// // });
// });
});
});
}
// imageUrl = await plugin.getProfileImageUrl(width: 100);
} else {
SellonRouter.pop(context);
}
// gagak
// final LoginResult loginResult = await FacebookAuth.instance
// .login(permissions: ["email", "public_profile"]);
// if (loginResult.status == LoginStatus.success) {
// final AccessToken accessToken = loginResult.accessToken;
// final userData = await FacebookAuth.instance.getUserData();
//
// final OAuthCredential credential =
// FacebookAuthProvider.credential(accessToken.token);
//
// print("credential ${credential.accessToken}");
// print("ascess token ${accessToken.token}");
//
// if (userData != null) {
// Preferences.getFirebase().then((token) {
// ApiSellon.createDefaultParams((parameter) {
// parameter.set("email", userData["email"]);
// parameter.set("fcm_token", token);
// parameter.set("device", Device.get().isIos ? "ios" : "android");
// parameter.set("fb_id", accessToken.userId);
//
// apiLoginMediaSosial(context, parameter, RegisterWith.facebookSign,
// accessToken.userId, userData["email"], userData["name"],
// page: page);
// });
// });
// } else {
// SellonRouter.pop(context);
// }
// } else {
// SellonRouter.pop(context);
// // login was not successful, for example user cancelled the process
// }
// Create a credential from the access tokn
}