saveToCollection<T> method

Future saveToCollection<T>({
  1. bool inBackpack = false,
})
inherited

Save an item to a collection E.g. List of numbers

User userAnthony = new User(name: 'Anthony'); await userAnthony.saveToCollection('mystoragekey');

User userKyle = new User(name: 'Kyle'); await userKyle.saveToCollection('mystoragekey');

Get the collection back with the user included. List

The key is the collection you want to access, you can also save the collection to the Backpack class.

Implementation

// ignore: avoid_shadowing_type_parameters
Future saveToCollection<T>({bool inBackpack = false}) async {
  if (_key == null) {
    NyLogger.error(
        'static StorageKey key = "${(runtimeType.toString()).snakeCase}" is not defined for ${runtimeType.toString()}, please define a key.'
        '\n\nExample:\nstatic StorageKey key = "${(runtimeType.toString()).snakeCase}";\n${runtimeType.toString()}() : super(key: key);'
        '');
    return;
  }
  await NyStorage.addToCollection<T>(_key!, item: this);
  if (inBackpack == true) {
    Backpack.instance.save(_key!, this);
  }
}