简体   繁体   中英

flutter secure storage how to store bearer token?

I try to store bearer access token to flutter secure storage. But I only able to access to body part details. i print jsonDecode(res.body) i can get all the details. but i write await storage.write(key: "token", value: data["access_token"]); i get null return.

How can I access to Body>Data > Accesstoken to get token and storage into secure storage?

                         var data = jsonDecode(res.body);
                         
                                            
                          await storage.write(key: "token", value: data["access_token"]);
                        
                         
                        
                          Navigator.pushReplacement(
                              context, SlideRightRoute(page: ooww()));
                          break;

enter image description here

The token is inside the key data. So you have to use

var data = jsonDecode(res.body);              
await storage.write(key: "token", value: data['data']["access_token"]);
                        

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM