Merge branch 'branch' of https://github.com/kleponijo/klimatologi into branch
This commit is contained in:
commit
80fe215313
|
|
@ -16,7 +16,7 @@ class SignUpBloc extends Bloc<SignUpEvent, SignUpState> {
|
||||||
await _userRepository.setUserData(myUser);
|
await _userRepository.setUserData(myUser);
|
||||||
emit(SignUpSuccess());
|
emit(SignUpSuccess());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(SignUpFailure());
|
emit(SignUpFailure(e.toString()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,18 @@ sealed class SignUpState extends Equatable {
|
||||||
const SignUpState();
|
const SignUpState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [];
|
List<Object?> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
final class SignUpInitial extends SignUpState {}
|
final class SignUpInitial extends SignUpState {}
|
||||||
|
|
||||||
final class SignUpSuccess extends SignUpState {}
|
final class SignUpSuccess extends SignUpState {}
|
||||||
final class SignUpFailure extends SignUpState {}
|
final class SignUpFailure extends SignUpState {
|
||||||
|
final String? message;
|
||||||
|
const SignUpFailure([this.message]);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [message];
|
||||||
|
}
|
||||||
|
|
||||||
final class SignUpProcess extends SignUpState {}
|
final class SignUpProcess extends SignUpState {}
|
||||||
|
|
@ -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,23 @@ 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;
|
||||||
|
});
|
||||||
|
final message = (state as SignUpFailure).message ?? 'Registrasi gagal, silakan coba lagi';
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text(message)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Form(
|
child: Form(
|
||||||
|
|
@ -113,8 +130,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 +160,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