First index value is 10. Second index value is 5
I am expecting the next index value to be 10 * 5 = 50, but I am getting the same value for all the index. Why does this happen?
void takeCostingValue(String text, String index) {
Map < String, int > quantities = {};
try {
int number = int.parse(text);
quantities[index] = number;
var totalObj = quantities.entries.map((e) {
return e.value;
}).toList();
var result = totalObj[0] * totalObj[1];
setState(() {
_costtextController = result as TextEditingController;
});
}
}
ListView.builder(
itemCount: costNameListData.length,
itemBuilder: (context, index) {
return TextField(
controller: _costtextController,
onChanged: (text) {
takeCostingValue(
text, index);
},
),
},
),
2
Answers
},), ], ), ); }
you should provide different TextEditingController for every TextField in yours
ListView:
_fabricCostTextController, _averageCostTextController and _costtextController
. this should be the different instance of TextEditingController.in other words, you can not use
_costtextController
for every TextField.