listflutterdart

How to remove item from list and return new list without removed item in flutter


I have a list of string as List<String> temp = ['a', 'b', 'c', 'd']; I want to modify and remove specific item from the list and return new list without the removed item.

For example, if I want to remove index 2, what I want to get is ['a', 'b', 'd'] removeAt doesn't work since it just returns removed string item...


Solution

  • You can use cascade notation to return the list when you call removeAt.

    void main() {
      print(['a', 'b', 'c', 'd']..removeAt(2));
    }