lesnitsky / flutter_localstorage

📦 LocalStorage for Flutter
MIT License
301 stars 60 forks source link

local storage data not refresh #64

Closed tomriddle7 closed 2 years ago

tomriddle7 commented 3 years ago

I made memo app using two screen.

main.dart

floatingActionButton: FloatingActionButton(
        onPressed: Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => WritePage()),
    );
  },
        tooltip: 'AddMemo',
        child: Icon(Icons.add),
      ),

WritePage.dart

_addItem() {
    setState(() {
      var memoList = storage.getItem('timeline_app');
      MemoList list = new MemoList();
      list.items = List<Memo>.from(
        (memoList as List).map(
              (item) => Memo(
                id: item['id'],
                title: item['title'],
                text: item['text'],
                createdTime: item['createdTime'],
                editedTime: item['editedTime'],
                done: item['done'],
          ),
        ),
      );
      final item = new Memo(
        id: 0,
        title: this.title,
        text: this.text,
        createdTime: DateTime.now().toString(),
        editedTime: DateTime.now().toString(),
        done: false
      );
      list.items.add(item);
      storage.setItem('timeline_app', list.toJSONEncodable());
    Navigator.pop(context);
    });
  }

When I create memo, it save to local storage but main screen is not change.

What problem in my code?

lesnitsky commented 2 years ago

very hard to say what's wrong with your code based on example you've provided. Could you please create a minimalistic example repository demonstrating the issue?