hello, permissions ask, I want to save the token via sharedpreferences but when I login the app doesn't want to go to the home page, but when I refresh the token, it is saved and goes straight to the home page. is there something wrong in writing my code.
CodePudding user response:
Create a method (like "checkIfUserExist()" call in initState) to check if the user is already login to your app and then accordingly they will go to the next screen.
class _HomePageState extends State<HomePage> {
@override
void initState() {
checkIfUserExist();
super.initState();
}
Future<void> checkIfUserExist() async {
final SharedPreferences _prefs = await SharedPreferences.getInstance();
String userToken = _prefs.getString(Constant.token) ?? '';
if (userToken != '') {
// navigation to Home screen
} else {
// navigation to Signup screen
}
}
...