这个变量在一个类中,我想把它称为/从另一个类中使用它

时间:2018-05-17 14:09:46

标签: android variables dart flutter

 Future<String> getData() async {
if (!email.contains("@")) {
  print("invalid email");
}

print("Your email is " + email + " and your password is " + password);
http.Response response = await http.post(
    Uri.encodeFull("https://api.wkend-eve.com/auth/login"),
    headers: {"Accept": "application/json"},
    body: {"email": email, "password": password});

Map<String, dynamic> x = json.decode(response.body);
print(x["access_token"]);
print(x["expires_in"]);
print(response.statusCode);


String acess_token = x["access_token"]; 

//我想调用变量:  字符串acess_token = x [&#34; access_token&#34;];
来自另一个班级

1 个答案:

答案 0 :(得分:0)

创建一个 Common 类,并在该类中创建一个静态变量 accessToken

Common.accessToken

然后,您可以在整个应用中使用accessToken。