Closed azazadev closed 4 years ago
When you navigate away from the HomeView is should dispose everything. When you come back it should be a new viewmodel that gets built and onModeReady should trigger. Make sure you're not disabling dispose, or telling stacked to only call onViewmodelReady once.
thanks for quick answer, I'm using Bottom Navigation Bar and based on wiki we should set the disposeViewModel as false and register ViewModel as singleton to avoid call to Firestore every time we switch between views :
my current Views have this configuration :
return ViewModelBuilder<HomeViewModel>.reactive(
disposeViewModel: false,
fireOnModelReadyOnce: true,
viewModelBuilder: () => locator<HomeViewModel>(),
onModelReady: (model) => model.listenToPosts(),
I have test multiple options but no success :(
I have found this solution :
void main() {
// Register all the models and services before the app starts
setupLocator();
runApp(
/// Wrap your App widget in the Phoenix widget
Phoenix(
child: MyApp(),
),
);
}
onPressed: () async {
await model.signOut();
Phoenix.rebirth(context);
model.navigateToWelcomePage();
locator.reset();
setupLocator();
}
and its work now :) , please let me know if you agree with this that I can close issue
Thanks again for help
I'm using Firebase Authentication Tutorial to Loging with Email/Password and I have implement the Logout method in AuthenticationService
so the scenario is :
User_1 Login with email_1/passwod_1 and go to HomeView and in HomeView the onModelReady is trigger for HomeViewModel
onModelReady: (model) => model.listenToPosts() -> data of user_1 is loaded From FireStore
User_1 Logout -> Trigger signOut method and navigate To WelcomePage
in WelcomePage I'm trying to Login with User_2 email_2/passwod_2
Expected :
onModelReady is trigger in HomeView and the data of user_2 is loaded From FireStore
Observed :
onModelReady is not Triggered in HomeView and the data of user_1 is loaded From FireStore
when I close and open again the app the data of user_2 is Loaded
Question : How I can clean user_1 data after Logout or how I can force all ViewModel to be rebuild again after Logout