Home > OS >  Does using 2 same Provider Consumer in one widget tree rebuild all different consumer value?
Does using 2 same Provider Consumer in one widget tree rebuild all different consumer value?

Time:11-13

Im trying to build my app as good as possible using provider. If i put same consumer provider in one widget like this for example

   Column(
                children: [
                  Consumer<Provider1>(
                    builder: (context, value, child) {
                      return Text(value.text1);
                    },
                  ),
                  Consumer<Provider1>(
                    builder: (context, value, child) {
                      return Text(value.text2);
                    },
                  ),
                ],
              ),

if i update text1 value and notifylistener() does the text2 or the other widget with the same provider get rebuild too ?

CodePudding user response:

Yes,it does rebuild all consumers value. You can use Selector for update only that widget like this

return Selector<Provider1, String>(
      builder: (context, text1, child) {
        return Text(text1);
      },
      selector: ((context, provider1) => provider1.text1),
    ); 
  • Related