Closed saravanans55 closed 3 years ago
could you please also share a piece of code which sets the item to the localstorage?
@lesnitsky for your reference,
` final LocalStorage storage = new LocalStorage('bskp_app');
Future userAuthAPI(username, password) async {
var inputObj = {'email': username, 'password': password, 'targetDomainKey': DOMAIN_KEY};
final url = "${API_BASE_PATH}/domain/login";
Map<String, String> headers = {'Content-Type': 'application/json'};
final response = await http.post(
Uri.parse(url),
headers: headers,
body: jsonEncode(inputObj)
);
var resultObj = {};
var jsonData = json.decode(response.body);
if(response.statusCode == 200){
resultObj = {
"status" : true,
"result" : jsonData,
};
storage.setItem('userObj', jsonData);
}else{
resultObj = {
"status" : false,
"result" : jsonData,
};
storage.setItem('userObj', {});
}
return resultObj;
}`
setItem
returns Future
so should be await
-ed
if(response.statusCode == 200){
resultObj = {
"status" : true,
"result" : jsonData,
};
await storage.setItem('userObj', jsonData);
^^^^ THIS IS IMPORTANT
}
Thanks for the help @lesnitsky. I'll try and come back soon.
@lesnitsky I tried But facing the same problem. This package working perfectly when I didn't close or clear the app from the recent apps list. If I close the apps it returns a null value.
2021-09-06 16:39:57.754 28880-28880/io..iotplatform D/SurfaceView: UPDATE null, mIsCastMode = false 2021-09-06 16:39:57.925 28880-28918/io..iotplatform I/flutter: storage.ready=======================> 2021-09-06 16:39:57.925 28880-28918/io..iotplatform I/flutter: null 2021-09-06 16:39:58.195 28880-28880/io..iotplatform I/FLTFireBGExecutor: Creating background FlutterEngine instance, with args: [] 2021-09-06 16:39:58.581 28880-28880/io..iotplatform I/FLTFireMsgService: FlutterFirebaseMessagingBackgroundService started! 2021-09-06 16:39:59.156 28880-28902/io..iotplatform I/kap.iotplatfor: ProcessProfilingInfo new_methods=0 is saved saved_to_disk=0 resolve_classes_delay=8000 2021-09-06 16:40:02.849 28880-28918/io..iotplatform I/flutter: isLoggedIn=======================>userObj 2021-09-06 16:40:02.849 28880-28918/io..iotplatform I/flutter: null 2021-09-06 16:40:03.156 28880-28918/io..iotplatform I/flutter: storage.ready=======================> 2021-09-06 16:40:03.156 28880-28918/io..iotplatform I/flutter: null
Hi @lesnitsky I troubleshoot the problem. In this app, I used three different localstorage packages. One of the packages affecting this one. I tried your package with another sample project it's working perfectly. Thanks for your help ❤️.
I'm using the below code in my flutter mobile app. It does not persist in storage value. When I close and reopen the mobile app it's automatically cleared.
My Code: Future isLoggedIn() async { bool flag = false;
}