简体   繁体   中英

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

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);
}
}

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.

SharedPrefernces doesn't prompt the user for permissions, as it's key/value pair register. Can you explain what are you trying to achieve?

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