Skip to content

How to rebuild a specific widget in a list? #3576

Answered by gdurandrexel
Dabbit-Chan asked this question in Q&A
Discussion options

You must be logged in to vote

What you probably should do is reverse the dependency:

@riverpod
Future<List<RebuildEntity>> rebuild(RebuildRef ref) async {
  final serverEntities = await Future.delayed(const Duration(seconds: 1)); // network request

  return serverEntities;
}

@riverpod
class RebuildItem extends _$RebuildItem {
  @override
  FutureOr<RebuildEntity> build(int index) async {
    final serverEntities = await ref.watch(rebuildProvider.future);

    return RebuildEntity(serverEntities[index]);
  };

  void changeState(int index, bool value) {
    final entity = RebuildEntity(
      index: index,
      selected: value,
    ); 
    // or more likely: final currentEntity = state.requireValue;
    // and then …

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@Dabbit-Chan
Comment options

@gdurandrexel
Comment options

@Dabbit-Chan
Comment options

@gdurandrexel
Comment options

Answer selected by Dabbit-Chan
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants