0
I have a function that performs login and I need to save the token on storage
:
login() async {
setState(() { isLoading = true; });
final response = await http.post('https://xxx.net/api/login',
body: {
"email": emailController.text,
"senha": senhaController.text,
});
if (response.statusCode == 202) {
Toast.show("Login ok", context, duration: Toast.LENGTH_LONG, gravity: Toast.CENTER);
// Write value
await storage.write(key: 'token', value: response.body.token);
} else {
Toast.show("Email ou senha incorreto", context, duration: Toast.LENGTH_LONG, gravity: Toast.CENTER);
}
setState(() { isLoading = false; });
}
However, I’m getting:
The getter 'token' isn’t defined for the class 'String'. Try importing the library that defines 'token', correcting the name to the name of an existing getter, or Defining a getter or field named 'token'
How can I make a getter for my Sponse?