Why my if statements doesn't work in flutter?
I have this app that do login with mysql and flutter So I wanted to do autologin so I went to phpmyadmin and set a boolean called it token and In my app I get its value and said if the token = 1 so the user is already logged in so I will see his level wither he is a member or an admin and navigate him to his page but the problem lies here, I can’t put if statements inside another statements or that is what I think so any help, Also new to flutter 🙂 edit:
void fetchData() async { setState(() { email = emailController.text; password = passwordController.text; }); try { final response = await http.post('http://192.168.137.1/login.php', body: { 'email': email, 'password': password, }); if (response.statusCode == 200) { setState(() { userdata = json.decode(response.body); }); } } catch (e) { print(e); } } void login() async { userdata.forEach((element) { userType = element['level']; }); if (userType == 'Student') { print('Student'); Navigator.pushReplacementNamed(context, '/StudentsPage'); } else if (userType == 'Teacher') { print('Teacher'); Navigator.pushReplacementNamed(context, '/TeacherPage'); } else { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: Text('Error'), content: Text('Please make sure that you have an internet connection '), actions: [ FlatButton( child: Text("Ok"), onPressed: () { Navigator.of(context).pop(); }, ) ], ); }, ); } }