skip to Main Content

I am trying to save data in local storage by using get storage. I created a instance of get storage (box) and write data in it in our services screen.
Here I created a instance of get storage

Here I write data in box
So I am trying to read this data from another screen of project but a error occur.
Here box can not be recognized

Please give your solutions Please.
Thanks

2

Answers


  1. to read data from get storage you need to use box.read(key):

    in your case if you want to read Name:

    var name = box.read('Name');
    
    Login or Signup to reply.
  2. You can write this way.

    final box = GetStorage();
    box.write('name', 'John');
    

    or

    GetStorage().write('name', 'John');
    

    You can read this way.

    final box = GetStorage();
    String name = box.read('name');
    

    or

    String name = GetStorage().read('name');
    

    Remember: you must initialize get storage before using it.

    void main() async {
      await GetStorage.init();
      runApp(MyApp());
    }
    

    For more details you can visit documentation here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search