commit
cea0a9dc1c
|
|
@ -57,8 +57,6 @@ class _SignInScreenState extends State<SignInScreen> {
|
||||||
validator: (val) {
|
validator: (val) {
|
||||||
if (val!.isEmpty) {
|
if (val!.isEmpty) {
|
||||||
return 'Please fill in this field';
|
return 'Please fill in this field';
|
||||||
} else if (!RegExp(r'^[\w-\.]+@([\w-]+.)+[\w-]{2,4}$').hasMatch(val)) {
|
|
||||||
return 'Please enter a valid email';
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -77,8 +75,6 @@ class _SignInScreenState extends State<SignInScreen> {
|
||||||
validator: (val) {
|
validator: (val) {
|
||||||
if (val!.isEmpty) {
|
if (val!.isEmpty) {
|
||||||
return 'Please fill in this field';
|
return 'Please fill in this field';
|
||||||
} else if (!RegExp(r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~`)\%\-(_+=;:,.<>/?"[{\]}\|^]).{8,}$').hasMatch(val)) {
|
|
||||||
return 'Please enter a valid password';
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,12 @@ class _SignUpScreenState extends State<SignUpScreen> {
|
||||||
bool obscurePassword = true;
|
bool obscurePassword = true;
|
||||||
bool signUpRequired = false;
|
bool signUpRequired = false;
|
||||||
|
|
||||||
|
bool containsUpperCase = false;
|
||||||
|
bool containsLowerCase = false;
|
||||||
|
bool containsNumber = false;
|
||||||
|
bool containsSpecialChar = false;
|
||||||
|
bool contains8Length = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocListener<SignUpBloc, SignUpState>(
|
return BlocListener<SignUpBloc, SignUpState>(
|
||||||
|
|
@ -30,12 +36,22 @@ class _SignUpScreenState extends State<SignUpScreen> {
|
||||||
setState(() {
|
setState(() {
|
||||||
signUpRequired = false;
|
signUpRequired = false;
|
||||||
});
|
});
|
||||||
|
// User sudah terdaftar dan auth state akan otomatis update via AuthenticationBloc
|
||||||
|
// Tungur sebentar agar Firestore selesai menyimpan data
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Registrasi berhasil! Mengarahkan...')),
|
||||||
|
);
|
||||||
} else if (state is SignUpProcess) {
|
} else if (state is SignUpProcess) {
|
||||||
setState(() {
|
setState(() {
|
||||||
signUpRequired = true;
|
signUpRequired = true;
|
||||||
});
|
});
|
||||||
} else if (state is SignUpFailure) {
|
} else if (state is SignUpFailure) {
|
||||||
return;
|
setState(() {
|
||||||
|
signUpRequired = false;
|
||||||
|
});
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Registrasi gagal, silakan coba lagi')),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Form(
|
child: Form(
|
||||||
|
|
@ -113,8 +129,6 @@ class _SignUpScreenState extends State<SignUpScreen> {
|
||||||
validator: (val) {
|
validator: (val) {
|
||||||
if (val == null || val.isEmpty) {
|
if (val == null || val.isEmpty) {
|
||||||
return 'Please fill in this field';
|
return 'Please fill in this field';
|
||||||
} else if (!RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$').hasMatch(val)) {
|
|
||||||
return 'Please enter a valid email';
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
@ -145,8 +159,6 @@ class _SignUpScreenState extends State<SignUpScreen> {
|
||||||
validator: (val) {
|
validator: (val) {
|
||||||
if (val == null || val.isEmpty) {
|
if (val == null || val.isEmpty) {
|
||||||
return 'Please fill in this field';
|
return 'Please fill in this field';
|
||||||
} else if (val.length < 6) {
|
|
||||||
return 'Password minimal 6 karakter';
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,24 @@ class FirebaseUserRepo implements UserRepository {
|
||||||
if (firebaseUser == null) {
|
if (firebaseUser == null) {
|
||||||
yield MyUser.empty;
|
yield MyUser.empty;
|
||||||
} else {
|
} else {
|
||||||
yield await userCollection.doc(firebaseUser.uid).get()
|
try {
|
||||||
.then((value) => MyUser.fromEntity(MyUserEntity.fromDocument(value.data()!)));
|
final userData = await userCollection.doc(firebaseUser.uid).get();
|
||||||
|
if (userData.exists && userData.data() != null) {
|
||||||
|
yield MyUser.fromEntity(MyUserEntity.fromDocument(userData.data()!));
|
||||||
|
} else {
|
||||||
|
// User baru yang belum ada data di Firestore, tunggu sebentar
|
||||||
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
final retryData = await userCollection.doc(firebaseUser.uid).get();
|
||||||
|
if (retryData.exists && retryData.data() != null) {
|
||||||
|
yield MyUser.fromEntity(MyUserEntity.fromDocument(retryData.data()!));
|
||||||
|
} else {
|
||||||
|
yield MyUser.empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log('Error fetching user data: $e');
|
||||||
|
yield MyUser.empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -63,6 +79,8 @@ class FirebaseUserRepo implements UserRepository {
|
||||||
await userCollection
|
await userCollection
|
||||||
.doc(myUser.userId)
|
.doc(myUser.userId)
|
||||||
.set(myUser.toEntity().toDocument());
|
.set(myUser.toEntity().toDocument());
|
||||||
|
// Tunggu sebentar agar data tersimpan dengan baik sebelum stream update
|
||||||
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e.toString());
|
log(e.toString());
|
||||||
rethrow;
|
rethrow;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue