'Flutter: How to update ValueNotifier for individual List item
I have a List builder with is creates cards with content. In this card i have a button and Text widget. Basically, i want to update Text widget when i press the button. I tried to use ValueNotifier and it worked. But it updating values of every List item.
Here is main functionality:
I created ValueNotifier variable
class SelectedOrganizationStructure extends StatefulWidget {
static ValueNotifier<String> lastLoginDate = ValueNotifier('Last login');
final List<OrganizationUnitEntity> organizationStructure;
const SelectedOrganizationStructure(this.organizationStructure, {Key? key})
: super(key: key);
@override
State<SelectedOrganizationStructure> createState() =>
_SelectedOrganizationStructureState();
}
And i set it to Text widget Text(SelectedOrganizationStructure.lastLoginDate.value), and when i press the button i set it's value to current date like this:
final _dateTime = DateTime.now();
final _loginDate = DateFormat('dd.MM HH:mm').format(_dateTime).toString();
onTap: () {
SelectedOrganizationStructure.lastLoginDate.value = _loginDate
},
How i said before, this sets current date for all the card item in list builder. How can i make it update only card in witch button was pressed?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
