146 lines
5.7 KiB
Dart
146 lines
5.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:google_sign_in/google_sign_in.dart';
|
|
import 'package:initial_folder/providers/firebase_authentication_provider.dart';
|
|
import 'package:initial_folder/providers/incomplete_profile_provider.dart';
|
|
import 'package:initial_folder/providers/registrasi_google_provider.dart';
|
|
import 'package:initial_folder/screens/home/home_screen.dart';
|
|
import 'package:initial_folder/screens/login/components/get_user_data.dart';
|
|
import 'package:initial_folder/screens/login/login_with_email/login_email_screen.dart';
|
|
import 'package:initial_folder/screens/profile/account_sign_in/incomplete_profile_screen.dart';
|
|
import 'package:initial_folder/screens/registrasi/registrasi_with_email/registrasi_email_screen.dart';
|
|
import 'package:initial_folder/screens/splash/splash_screen_login.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../../../size_config.dart';
|
|
import '../../../theme.dart';
|
|
|
|
class RegistrationGoogle {
|
|
Future handleRegistrationGoogle(BuildContext context) async {
|
|
final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
|
|
final googleAuth = await googleUser?.authentication;
|
|
final name = googleUser?.displayName;
|
|
final email = googleUser?.email;
|
|
final provider =
|
|
Provider.of<FirebaseAuthenticationProvider>(context, listen: false);
|
|
if (await provider.googleLogin()) {
|
|
await getUserData(context);
|
|
|
|
Condition.loginFirebase = true;
|
|
|
|
IncompleteProfileProvider userInfoIncomplete =
|
|
Provider.of<IncompleteProfileProvider>(context, listen: false);
|
|
|
|
// [!CHECKPOINT!]:
|
|
await userInfoIncomplete.getUserInfoIncomplete();
|
|
if (userInfoIncomplete.isUserInfoComplete == null) {
|
|
Navigator.of(context).pushNamedAndRemoveUntil(
|
|
LoginEmail.routeName, (Route<dynamic> route) => false);
|
|
return;
|
|
}
|
|
|
|
if (userInfoIncomplete.isUserInfoComplete!) {
|
|
Navigator.of(context).pushNamedAndRemoveUntil(
|
|
HomeScreen.routeName, (Route<dynamic> route) => false);
|
|
} else {
|
|
Navigator.of(context).pushNamedAndRemoveUntil(
|
|
IncompleteProfile.routeName, (Route<dynamic> route) => false);
|
|
}
|
|
} else if (googleAuth != null && name != null && email != null) {
|
|
// data ditemukan, gunakan di sini
|
|
Provider.of<RegistrasiGoogleProvider>(context, listen: false)
|
|
.setNameAndEmail(name, email);
|
|
|
|
Navigator.pushReplacementNamed(context, RegistrationEmail.routeName);
|
|
} else {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
insetPadding: EdgeInsets.symmetric(horizontal: 25, vertical: 20),
|
|
content: Container(
|
|
alignment: AlignmentDirectional.bottomCenter,
|
|
height: 50,
|
|
child: Text(
|
|
'Ada kendala dalam mendaftar, coba lagi atau periksa akun anda',
|
|
style: primaryTextStyle.copyWith(
|
|
fontSize: getProportionateScreenWidth(12), letterSpacing: 1),
|
|
),
|
|
),
|
|
actions: [
|
|
Container(
|
|
height: 30,
|
|
alignment: AlignmentDirectional.topEnd,
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Text('Tutup',
|
|
style: primaryTextStyle.copyWith(
|
|
fontSize: getProportionateScreenWidth(12),
|
|
letterSpacing: 1,
|
|
color: primaryColor)),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// Future handleRegistrationGoogle(BuildContext context) async {
|
|
// final provider =
|
|
// Provider.of<FirebaseAuthenticationProvider>(context, listen: false);
|
|
// if (await provider.googleLogin()) {
|
|
// await getUserData(context);
|
|
|
|
// Condition.loginFirebase = true;
|
|
|
|
// IncompleteProfileProvider userInfoIncomplete = Provider.of<IncompleteProfileProvider>(context, listen: false);
|
|
// await userInfoIncomplete.getUserInfoIncomplete();
|
|
// if (userInfoIncomplete.isUserInfoComplete) {
|
|
// Navigator.of(context)
|
|
// .pushNamedAndRemoveUntil(
|
|
// HomeScreen.routeName,
|
|
// (Route<dynamic> route) => false);
|
|
// } else {
|
|
// Navigator.of(context)
|
|
// .pushNamedAndRemoveUntil(
|
|
// IncompleteProfile.routeName,
|
|
// (Route<dynamic> route) => false);
|
|
// }
|
|
// } else {
|
|
// showDialog(
|
|
// context: context,
|
|
// builder: (context) => AlertDialog(
|
|
// insetPadding: EdgeInsets.symmetric(horizontal: 25, vertical: 20),
|
|
// content: Container(
|
|
// alignment: AlignmentDirectional.bottomCenter,
|
|
// height: 50,
|
|
// child: Text(
|
|
// 'Ada kendala dalam mendaftar, coba lagi atau periksa akun anda',
|
|
// style: primaryTextStyle.copyWith(
|
|
// fontSize: getProportionateScreenWidth(12), letterSpacing: 1),
|
|
// ),
|
|
// ),
|
|
// actions: [
|
|
// Container(
|
|
// height: 30,
|
|
// alignment: AlignmentDirectional.topEnd,
|
|
// child: GestureDetector(
|
|
// onTap: () {
|
|
// Navigator.of(context).pop();
|
|
// },
|
|
// child: Text('Tutup',
|
|
// style: primaryTextStyle.copyWith(
|
|
// fontSize: getProportionateScreenWidth(12),
|
|
// letterSpacing: 1,
|
|
// color: primaryColor)),
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// );
|
|
// }
|
|
// }
|
|
}
|