Question: //It keeps saying my token is wrong, Failed to Load PlaceInfo class LoginAPI { Future setToken(String value) async { final SharedPreferences prefs = await SharedPreferences.getInstance();

//It keeps saying my token is wrong, Failed to Load PlaceInfo

class LoginAPI { Future setToken(String value) async {

final SharedPreferences prefs = await SharedPreferences.getInstance();

return prefs.setString('token', value); }

Future getToken() async { final SharedPreferences prefs = await SharedPreferences.getInstance();

return prefs.getString('token'); }

Future signIn(String email, String password) async { String loginUrl = loginUrl; String token = await getToken();

Map body = {"Email" : email, "Password" : password, "token" : token};

var response = await http.post(loginUrl, headers: { 'Content-Type': 'application/json', 'accept': 'application/json', 'Authorization': 'Bearer $token', }, body: body);

//Need to check the api status

if(response.statusCode == 200){

var jsonResponse; jsonResponse = json.decode(response.body);

print("Response status: ${response.statusCode}");

print("Response status: ${response.body}");

var token = json.decode(response.body).token;

setToken(token); return json.decode(response.body); }

else{ print("Response status: ${response.body}"); } } }

// where i call it

Future> getPlace(String place) async{

String token; LoginAPI().getToken().then((value) { token = value; });

final response = await http.get(loginUrl+ "/places?q=$place",

headers: { 'Content-Type': 'application/json', 'accept': 'application/json', 'Authorization': 'Bearer $token', });

print('Token : $token');

print(response); if(response.statusCode == 200){

Iterable l = jsonDecode(response.body);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!