Search code examples
fluttersembast

sembast recommended way to create a store


I am confused by the fact that there are two ways to create a Store :

var store = sembast.StoreRef<String, List<dynamic>>.main();
await store.record('username').put(db, 'my_username');
final usernameDbStore = sembast.intMapStoreFactory.store('username');

Is the 1st (.main) meant to keep the .db settings ? Is there another difference between the two ?


Solution

  • The main() is just a convenient shortcut to a store named _main. Some applications sometimes need a single store so don't bother about giving it a name.

    An application can have multiple named stores too (_main + some others). There is no difference in using _main vs another store nor any guidelines/recommendations. Typically, I personnally have a store named prefs for my application preferences or singletons and then one store per entity type (notes, contacts...).