title: Making unique ID list tile in Flutter
body: <p>I have this code that I can't get to work properly. I have a Food class and I have initialized the name, price, and unique ID strings on it. I made the unique ID to be Uuid().v4(), which would give each food item a random string.</p>
  <p><strong>FOOD CLASS</strong></p>
  <pre><code>  class Food {
    String name;
    String price;
    String uniqueID = Uuid().v4();
    
    
    Food({this.name,
    this.price,
    this.uniqueID})}
  </code></pre>
  <p>On another page I have a Provider function that would add items in the cart, it is a list of string items (this may not be the best option). Here is the code for it:</p>
  <pre><code>class CartItemsModel extends ChangeNotifier {
    List&lt;String&gt; _cartItems = [];
  
    List&lt;String&gt; get cartItems =&gt; _cartItems;
  
    addCartItem(String item) {
      _cartItems.add(item);
      notifyListeners();
    }
  </code></pre>
  <p>Now, on another page, I am calling that food to be added to the cart, it is an icon with onPressed above function:</p>
  <pre><code>return ListTile(
        trailing: Container(
                 padding:
                  EdgeInsets.only(top: 15.0),
                   child: IconButton(
                     icon: Icon(Icons.add),
                                                  
                       onPressed: () =&gt;
                                                     
                          model.addCartItem(
                          &quot;${food.name}, Calories: ${food.calories}        ${food.price} din\nVegan: ${food.isVegan},  ${Uuid().v4()}&quot;)),
  </code></pre>
  <p>Now, you see that I have Uuid on there (without my uniqueID from Food class, because for some reason it doesn't work). I have the Uuid, so that there isn't an error with multiple duplicate items if the button would be clicked twice, here's the error without it:</p>
  <p><a href="https://i.stack.imgur.com/zbY5f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zbY5f.png" alt="enter image description here" /></a></p>
  <p>The issue is that this works and is functional, but I have this ugly ID from the Uuid displayed on the final 'cart' window. Basically I want this ID to be invisible. Here is how it looks:</p>
  <p><a href="https://i.stack.imgur.com/SUvoc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SUvoc.png" alt="enter image description here" /></a></p>
  <p>And here is the code for the 'cart' screen:</p>
  <pre><code>  class _CartState extends State&lt;Cart&gt; {
    @override
    Widget build(BuildContext context) {
      return Consumer&lt;CartItemsModel&gt;(
        builder: (c, model, _) =&gt; Scaffold(
        body: SingleChildScrollView(
              child: Column(
                //on trailing i should have icon with clear function that will delete that item from the list
                children: model
                    .cartItems //maybe below can return ListView.separated like on the food list user, we'll see
                    
                    .map((e) =&gt;   
  </code></pre>
  <p>So to keep long story short, my uniqueID isn't used on here because for some reason it doesn't make each list tile item unique with its key, so it doesn't display and give me error when clicked twice, that's why temporatily I am using the Uuid trick.</p>
  <p>What I want is for this to work exactly like this, but without the ugly Uuid string to be seen. Is there simple I can do with it, maybe add something to the CartItemsModel code, a conditional, or something else?</p>
  <p>If I change the code in onPressed to this:</p>
  <pre><code>onPressed: () {
       if (!model.cartItems
                .contains(food)) {
                  model.addCartItem(Food);
                                      }
                                     }
  </code></pre>
  <p>I am getting error:</p>
  <pre><code>The argument type 'Type' can't be assigned to the parameter type 'String
  </code></pre>
  <p>Which is understandable because it is a List in CartItemsModel. Any ideas how to fix this and be it just so items can be added to 'cart'?</p>