Which permission to use for shared preferences? android(flutter)

1,611

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 ?

Share:
1,611
That Guy
Author by

That Guy

Well versed in Flutter, NodeJs, ExpressJs and GraphQL.

Updated on December 21, 2022

Comments

  • That Guy
    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
    That Guy almost 4 years
    So using the shared preferences I want to make sure the user is logged in
  • Amir Bennasr
    Amir Bennasr almost 4 years
    So 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
    That Guy almost 4 years
    It works perfectly in debug mode but in the release mode, it's not working so I assumed it's lacking permissions
  • That Guy
    That Guy almost 4 years
    Do I need to add a Future or something?
  • Amir Bennasr
    Amir Bennasr almost 4 years
    if you can show all the code it will be better. the full scenario