Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use the list as you do and as <code>cutch</code> mentioned manually add your own method to verify duplicates and sorting similar to the below.</p> <pre><code>import 'dart:html'; var someList = new List&lt;String&gt;(); String newItem = ''; void main() { newItem = 'item 3'; if(!itemExistsInList(someList, newItem)){ someList.add(newItem); sortList(someList); } // expected item 3 print(someList); newItem = 'item 1'; if(!itemExistsInList(someList, newItem)){ someList.add(newItem); sortList(someList); } // expected item 1, item 3 print(someList); newItem = 'item 3'; if(!itemExistsInList(someList, newItem)){ someList.add(newItem); sortList(someList); } // expected item 1, item 3. Same as previous as secondary item 3 was not added print(someList); } // returns true if the specified item already exists in the specified list // otherwise false bool itemExistsInList(List&lt;String&gt; list, String item){ return list.some((v) =&gt; v.indexOf(item) != -1); } // sorts the list void sortList(List&lt;String&gt; list){ list.sort((a, b) =&gt; a.compareTo(b)); } </code></pre> <p>You don't need to call the <code>sortList()</code> function every time you add, I only did this for demonstration. Only calling it when you actually need to is enough off course.</p> <p><code>.sort()</code>, <code>.some()</code> and <code>.indexOf</code> are explained in more detail under the collections section of the <a href="http://www.dartlang.org/docs/library-tour/#collections" rel="nofollow"><strong>DART library documentation</strong></a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload