I am using getX for state management in my app. The model files contains a list of items and I want to update to items but the updated value doesn't get updated on being changed.
The code for View:
body: ListView.builder(
itemCount: _antigens.fungus.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(_antigens.fungus[index]['name']),
onTap: () {
controller.updateValue(context, index);
});
}),
Controller:
updateValue(BuildContext context, int index) async {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Enter a value'),
content: TextField(
controller: controller,
keyboardType: TextInputType.number,
),
actions: [
ElevatedButton(
onPressed: () {
_antigen.fungus[index]['value'] = controller.text;
Get.back();
},
child: const Text('Ok'),
)
],
);
});
}
view to show updated value:
return Center(
child: Text(antigens.fungus[0]['value'].toString()),
);