Save dismissible state

635 Views Asked by At

How do I save the state of a dismissible? When the item is dismissed it stays dismissed upon closing and opening the app?

I'm relatively new to flutter and checked out saved preferences plugin but couldn't get it to work.

1

There are 1 best solutions below

0
On

You need some way to persist and restore the state of the application between launches. A common solution in Flutter is to use Redux, which is a unidirectional data flow architecture for managing state. This blog post from Xavi Rigau is quite a good introduction. There is an example app in the GitHub repository that extends the default counter example app to use redux.

In order to persist the state between app launches, you'll need to add the persistence layer. One option would be to use your own file storage middleware (see Xavi's post and the examples in the flutter_redux repository). Another approach would be to use the Flutter redux_persist library (I haven't used this one yet).

Note: Given the complexities and details involved, I haven't included code examples here, but there is plenty in the listed references.