I have a button which on initial click/tap/touch, it POST to API and return true or false based on auth.
onPressed: ()=>{ Provider.of<Login>(context, listen: false).login() .then((value) => { if(value == true) Navigator.pushReplacementNamed(context, '/home') }), },
Future<bool> login() async { try{ var payload = jsonEncode({ 'email': usrname, 'password': pswd }); Map<String,dynamic> response = await fetch.post(url, body:payload, headers: { 'Accept':'application/json', 'content-type': 'application/json' }) .then((value) => jsonDecode(value.body)); if(response['token'] != ''){ return true; } } catch(e){ errorMsg = e.toString(); notifyListeners(); return false; } return false; }
On successful authentication, it doesn't redirect to new screen as intended. Am I missing something or my logic is flawed?