Skip to content

Watch doesn't trigger rebuild on signal if used in a nested Builder #363

@SPiercer

Description

@SPiercer

there's another weird behaviour i have found when using signals in such way

so i have declared my signals as usual

final selectedPostSignal = signal<SelectedPost?>(null);

and in my widget down below i'm using

Watch.builder(
  builder: (_){
    return Column(
      children: [
        SomeWidget(),
        SomeOtherWidget(),
        if (selectedPostSignal.value?.id == post.id)
          PostDetails(post: post),
      ],
    )
  }
)

if i did this it would never work and never rebuild if somewhere else i changed selectedPostSignal

i have to assign it to a variable to work

Watch.builder(
  builder: (_){
    final selectedPost = selectedPostSignal.value;
    return Column(
      children: [
        SomeWidget(),
        SomeOtherWidget(),
        if (selectedPost?.id == post.id)
          PostDetails(post: post),
      ],
    )
  }
)

and volla!, magically it works.

please validate this with me rody, if that's a malpractice of me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions