Giter VIP home page Giter VIP logo

Comments (3)

agordn52 avatar agordn52 commented on May 16, 2024 2

Hi @RoxDevvv,

updateCollectionByIndex now available in nylo_framework v5.20.9 🔥

Here's an example of how to use it.

await NyStorage.updateCollectionByIndex(2, (item) {
      return 'New value';
}, key: 'my_storage_key');


// Example on a Model
await NyStorage.updateCollectionByIndex<User>(5, (User item) {
  item.name = "User Updated";
  item.email = "[email protected]";
  return item;
}, key: 'my_storage_key');

You can run this example to demo it working too:

await NyStorage.delete('coins');

await NyStorage.addToCollection('coins', item: 0);
await NyStorage.addToCollection('coins', item: 1);
await NyStorage.addToCollection('coins', item: 2); // update this
await NyStorage.addToCollection('coins', item: 3);

List<dynamic> coins = await NyStorage.readCollection('coins');
print('before');
for (var coin in coins) {
      print(coin);
}

// update
await NyStorage.updateCollectionByIndex(2, (item) {
      return 200;
}, key: 'coins');

print('\n');

print('after');
coins = await NyStorage.readCollection('coins');
// before
for (var coin in coins) {
      print(coin);
}

from nylo.

agordn52 avatar agordn52 commented on May 16, 2024 1

Hi @RoxDevvv,

This is a cool idea!

I'll work on it later today and hopefully push it up for tomorrow 🚀

from nylo.

RoxDevvv avatar RoxDevvv commented on May 16, 2024

maybe something builtin like that will be good

static Future updateInCollection<T>(int index, T newItem,
    {required String key}) async {
  List<T> collection = await readCollection<T>(key);
  if (collection.isEmpty || index < 0 || index >= collection.length) return;

  collection[index] = newItem;
  await saveCollection<T>(key, collection);
}

from nylo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.