Which permission to use for shared preferences? android(flutter)
Solution 1
So turns out the issue is, when you run the above code in debug mode, it runs fine but in release mode somehow the if statement which checks if the error is null wont work because apparently null isn't supported for release mode. Hence, using "" instead of null worked for me. Thanks for trying though.
Solution 2
SharedPrefernces doesn't prompt the user for permissions, as it's key/value pair register. Can you explain what are you trying to achieve ?
That Guy
Well versed in Flutter, NodeJs, ExpressJs and GraphQL.
Updated on December 21, 2022Comments
-
That Guy over 1 year
So im making a login page and it works fine when I run it in emulator but when I run the release version I saw that adding the internet permission in the xml file permits my app a connection. however im unable to find what permission to provide for shared preferences as it's not loggin in.
heres a part of the code:
if (jsonResponse['ErrorMesage'] != null) { print(jsonResponse['ErrorMesage']); showAlertDialog(context); } else { print("ok"); sharedPreferences.setString("Token", jsonResponse['Token']); Navigator.of(context).pushAndRemoveUntil( MaterialPageRoute(builder: (BuildContext context) => Home()), (Route<dynamic> route) => false); }
here's the code used to check:
checkLoginStatus() async { sharedPreferences = await SharedPreferences.getInstance(); if (sharedPreferences.getString("Token") == null) { Navigator.of(context).pushAndRemoveUntil( MaterialPageRoute(builder: (BuildContext context) => MyApp()), (Route<dynamic> route) => false); } }
-
That Guy almost 4 yearsSo using the shared preferences I want to make sure the user is logged in
-
Amir Bennasr almost 4 yearsSo from what i understand ,the function will check if the token is null it will redirect him to the main app , else it will redirect him to another page ? and what is the problem that is occuring ?
-
That Guy almost 4 yearsIt works perfectly in debug mode but in the release mode, it's not working so I assumed it's lacking permissions
-
That Guy almost 4 yearsDo I need to add a Future or something?
-
Amir Bennasr almost 4 yearsif you can show all the code it will be better. the full scenario