How can I update my List<Map<String,dynamic>> in flutter, I have tried using it like this controller.reportData.value[index]['customer'] and controller.reportData[index].value['customer]
Following is my code: Controller Class:
RxList<Map<String, dynamic>> reportData = <Map<String, dynamic>>[].obs;
Future<void> getReport() async {
await BaseClient.safeApiCall(
ApiConstants.CUSTOMER_ITEM_SUMMARY,
RequestType.post,
headers: await BaseClient.generateHeaders(),
data: {
'fromDate': fromDatePickerController.text,
'toDate': toDatePickerController.text
},
onSuccess: (json) {
reportData.clear();
json.data.forEach((data) {
reportData.add({
'customer': '${data['customerCompanyName']}',
'qty': '${data['quantity']}',
'amount': '\$${data['subTotal']}',
'cogs': '\$${data['cogs']}',
'net': '\$$net',
'gain': '$gain%',
});
});
},
onError: (e) {},
);
}
View Class:
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
itemCount: controller.reportData.length,
shrinkWrap: true,
padding: const EdgeInsets.symmetric(
vertical: 10,
),
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: ListTile(
title: Row(
children: [
Expanded(
flex: 5,
child: Text(
controller.reportData.value[index]['customer'],
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
style: context.bodyLarge.copyWith(
fontWeight: FontWeight.normal,
),
),
),
...
],
),
),
);
},
),
I have tried doing update(); and it doesn't work.