edit alur navigasi ke homescreen

This commit is contained in:
e32232340-Nadif 2026-02-14 18:53:08 +07:00
parent e722ad430c
commit afb99b16dd
2 changed files with 31 additions and 3 deletions

View File

@ -36,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(

View File

@ -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;