'How to split the elements in a list according to range of numbers in flutter
Am working on a project and I need to break down a list to a new list
eg I need to break down this kind of list [{ name: rice, quantity: 87, price: 8700}, {name: beans, quantity: 75, price: 7500}, {name:melon, quantity:55, price: 5500}]
to
[[{name:rice, quantity: 30, price:3000}], [{name:rice, quantity:30, price:3000}], [{name:rice, quantity:27, price:2700, name:beans,quantity: 3,price:300}][{name:beans, quantity:30, price:3000}], [{name:beans, quantity:30, price:3000}], [{name:beans, quantity:12, price:1200, name:melon, quantity: 18, price:1800}], [{name:melon, quantity:30, price:3000}], [{name: melon, quantity:7, price:700}]],
The list is being further split into smaller bits into 30's with price reduced accordingly and numbers from the next element will be added to complete the previous remainder making it 30.
Solution 1:[1]
var newList = []; ///Your desired list
///outerList is the list you want to iterate
for (var innerList in outerList){
newList.add(innerlist.first);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dyadee |