I have a variable like this:

LinkedHashMap _items = new LinkedHashMap();

With a web service I load other items (tmpItems) from the web and I need to add the items or assign them to the variable, depending on the value of the page variable.

If page = 1, I need to assign new items to _items variable, if page > 1 I need to addAll new items to _items variable.

Right now I have:

setState(() {
    _items.addAll(tmpItems ?? []);
});

I need something like:

setState(() {
    _page > 1 ? _items.addAll(tmpItems ?? []) : _items = tmpItems;
});

But I know this code is wrong.


Solution 1: creativecreatorormaybenot

You can simply use an if statement for this purpose:

setState(() {
  if (_page > 1) {
    _items.addAll(tmpItems ?? []);
  } else {
    _items = tmpItems ?? [];
  }
});