Search code examples
flutterlocal-storageflutter-webflutter-getx

Flutter web local storage issue with Getx


I have a question. After logging in, I save the token with get storage, then when I redirect to a new page with the url launcher, the existing token is lost and sometimes I get this problem and sometimes I don't. Below is how I write and read get storage

{
  final box = GetStorage();
  box.write("token", nvResponseLogin.value.auth!.token);
}

{
      final _box = GetStorage();
      String? token = _box.read("token");
      if (token == null) {
      token = "";
      }
}

Solution

    1. Basically it seems your code is not wrong.
    2. Make sure variable is 'box' or '_box'.
    3. Check the right token is saved or not before use. ex) print token right after saving the token to getStorage.