Update only the New Selected and the Previous Selected widget on a list view #1167
-
Basically I have a ListView with data and I have a selectedDataProvider:
When I clicked a widget on the ListView i want to change the color of the selected widget. but when I Is there a way to rebuild only the new selected widget and the previous selected (if has previous selected) This is my widget:
|
Beta Was this translation helpful? Give feedback.
Answered by
TimWhiting
Feb 10, 2022
Replies: 1 comment 3 replies
-
Use .select class MyWidget extends ConsumerWidget {
const MyWidget ({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
// Formatter for srp
final formatter = ref.watch(formatterProvider);
// Current index of the FormData
final index = ref.watch(currentFormDataIndex);
// Current FormData in the listView
final data = ref.watch(currentFormData);
// Search query
final query = ref.watch(queryFormDataProvider);
// Whether this is the currently selected formdata
final isSelected = ref.watch(selectedFormDataProvider.select((value) => value?.data == data));
return ListTile(
selectedTileColor: Colors.blue,
selected: isSelected,
title: Text(data.description),
);
}
} |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
b4ltz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use .select