Flutter - replacing a item in a list

You can do this:

integer.isNotEmpty
  ? integer.removeWhere((item)=>item.amount == 4) //removes the item where the amount is 4
  : null;
integers.insert(
  1,
  amount(
    id: DateTime.now().toString(),
    amount:34,
  ));

If you want to remove an item by using the index, you can use removeAt() method:

integer.isNotEmpty
  ? integer.removeAt(1) //removes the item at index 1
  : null;
integers.insert(
  1,
  amount(
    id: DateTime.now().toString(),
    amount:34,
  ));

If you know the index of the element you want to replace, you don't need to remove existing element from the List. You can assign the new element by index.

  integer[1] = amount(amount: 5, id: 'new_id');

Tags:

Dart

Flutter