我有flutter和button的登录表单:
FloatingActionButton(
onPressed: log_in,
)
我的log_in函数:
log_inc() async {
var headers = {
'Content-Type': 'text/html',
};
var data = '{"username":"XXXXX", "password":"XXXXX"}';
var url = Uri.parse('http://XXXXX/api/auth/get_tokens');
var res = await http.post(url, headers: headers, body: data);
if (res.statusCode != 200)
throw Exception('http.get error: statusCode= ${res.statusCode}');
var data_res = jsonDecode(res.body);
final storage = new FlutterSecureStorage();
await storage.write(key: "token", value: data_res["access_token"]);
var token = await storage.read(key: "token");
print(token);
return Home_page();
}
一切正常,我正在获取访问令牌并将其存储在FlutterSecureStorage中,但我无法重定向到Home_page。我做错了什么?
1条答案
按热度按时间ltqd579y1#
要导航到
Home_page
,可以使用Flutter中的Navigator
类。