我正在尝试在颤振中创建一个注册页面。使用 HTTP 包将数据发布到后端,然后我收到状态消息。我需要访问存储在 API 缓存中的 session_id(和 csrf 值),以便我可以在共享首选项中设置其值以进行进一步的会话管理。我发布数据的代码是:
Future registeruser(String firstname, String lastname,String email,String password,int
phone) async {
String apiUrl="api here";
final body ={"firstname":firstname,
"lastname":lastname,
"email":email,
"password":password,
"phone":phone,
};
final response= await http.post(apiUrl,headers:{'Content-type':
'Application/json','Accept':'Application/json'} ,body:body );
var convertedDatatoJson= jsonDecode(response.body);
return convertedDatatoJson;
}
var res =await registeruser(firstname, lastname, email, password, phone);
if(res.containsKey('status')){
setState(() {
message=res['status'];
});
if(res['status']==1){
Navigator.pop(context);
}
else{
print('error');
}
}
}},
但是我如何从 API 的缓存中获取数据并存储在共享首选项中,我对颤振很陌生,请帮助我。