Coder Social home page Coder Social logo

Comments (6)

rrousselGit avatar rrousselGit commented on July 20, 2024

I don't really understand what this is about.
Could you explain more?

from riverpod.

not-holar avatar not-holar commented on July 20, 2024

Let's say we took something like the Todo example, but made each TodoItem widget much more complex, so rebuilding them all at once when we change a field of only one item would be inefficient.

Right now all changes to a Todo are done through TodoList and you can only listen to the whole list at once.

You could wrap each list item in something like ValueListenable and then each item widget in ValueListenableBuilder for more granular rebuilds, but that would bring in a flutter dependency.

Basically what i'm asking about is a more modular state, where items of a list could change and notify individually without rebuilding the whole list

from riverpod.

hpn33 avatar hpn33 commented on July 20, 2024

on provider that was easy for me
i make my item with ChangeNotifier
class Item with ChangeNotfier {}
and when building widget list i put them on ChangeNotifierProvider.value

ChangeNotifierProvider.value(
value: item,
builder: ....)

and its worked
when item is change just that widget on list going change

but in riverpod is complex

from riverpod.

rrousselGit avatar rrousselGit commented on July 20, 2024

One solution is to pass the index/id to the item, then use a Computed.family (or Provider.family on 0.6.0-dev):

ListView.builder(
  itemBuilder: (context, index) => TodoItem(index),
);

...

final todoItemProvider = Computed.family<Todo, int>((watch, index) {
  return watch(todoListProvider.state)[index];
});

...

final int index;
Widget build(context) {
  final item = useProvider(todoItemProvider(index));
}

from riverpod.

arnoutvandervorst avatar arnoutvandervorst commented on July 20, 2024
  static final provider = StreamProvider.family
      .autoDispose<List<GroupEarning>, String>((_, groupId) {
    return GroupEarnings().streamList(groupId);
  });

This works on 0.6.0, very nice!

from riverpod.

rrousselGit avatar rrousselGit commented on July 20, 2024

The todo/marvel app showcase how you can avoid unnecessary item rebuild, so I will close this for now

from riverpod.

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.