Reputation: 39
I have a file Login.dart I had added a function to a button in flutter.
onPressed: () {
setState(() {
username = usernameController.text;
isUserLoggedIn = true;
});
print(username);
Navigator.pop(context);
},
As this function show that on button is pressed it will set isUserLoggedIn = true. Its working fine and value of the boolean is changing fine.
Now in my main.dart
class _NavigationPageState extends State<NavigationPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: isUserLoggedIn == false ? IntroAuthScreen() : HomePage(),
);
}
}
So now as the value of isUserLoggedIn is setted to true my code should redirect me to HomePage() but when i restart my app it still redirect me to IntroAuthScreen()
Upvotes: 0
Views: 136
Reputation: 105
That is because when you restart the app, isUserLoggedIn will revert back to its original value. You can save your app settings with shared_preferences
Upvotes: 2