Can we find a way to select only the states that need to be used, but with less code? #3963
Answered
by
gdurandrexel
Trung15010802
asked this question in
Q&A
-
Using multiple ref.watch select calls can lead to duplicated code but if not we might have potential performance issues. Example: final progressValueColor = ref.watch(
appColorsProvider.select(
(value) => value.progressValueColor,
),
);
final borderColor = ref.watch(
appColorsProvider.select(
(value) => value.borderColor,
),
);
final secondBgColor = ref.watch(
appColorsProvider.select(
(value) => value.secondBgColor,
),
); |
Beta Was this translation helpful? Give feedback.
Answered by
gdurandrexel
Feb 6, 2025
Replies: 1 comment
-
You can return a record. They support equality out of the box. If any value in the record changes, the resulting record is not equal to the previous one and you are notified. final colors = ref.watch(
appColorsProvider.select(
(value) => (progressValueColor: value.progressValueColor, borderColor: value.borderColor, secondBgColor: value.secondBgColor)
),
); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Trung15010802
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can return a record. They support equality out of the box.
If any value in the record changes, the resulting record is not equal to the previous one and you are notified.