title: I am having trouble iterating through an array of objects
body: <p>I am trying to go through an array of objects, I stored them in my SharedPreferences where I go the data from firebase and add the quantity for each object, now I only want to display the title, price, and quantity of the product in the cart. I was able to pull all the values belonging to the product to the cart screen but how to loop through the nested values in the cart screen is the problem. please can anyone help me still learning more on flutter?</p>
  <pre><code>Cart screen
  @override
    Widget build(BuildContext context) {
      SharedPreferences prefs = SharedPreferences.getInstance() as SharedPreferences;
      var cart = prefs.getStringList('userCart');
      return Row(
        children: [
          SizedBox(
            width: getProportionateScreenWidth(88),
            child: AspectRatio(
              aspectRatio: 0.88,
              child: Container(
                padding: EdgeInsets.all(10),
                decoration: BoxDecoration(
                  color: Color(0XFFF5F6F9),
                  borderRadius: BorderRadius.circular(15),
                ),
                child: Image.network(cart![0]),
                // child: Image.network(cart.product.images[0]),
              ),
            ),
          ),
          SizedBox(
            width: getProportionateScreenWidth(20),
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                cart.first,
                // cart.product.title,
                style: TextStyle(fontSize: 16, color: Colors.black),
                maxLines: 2,
              ),
              const SizedBox(
                height: 10,
              ),
              Text.rich(
                TextSpan(
                  text: &quot;\$${cart.product.price}&quot;,
                  style: TextStyle(
                    color: kPrimaryColor,
                  ),
                  children: [
                    TextSpan(
                      text: &quot; x${cart.numOfItem}&quot;,
                      style: TextStyle(
                        color: kTextColor,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          )
        ],
      );
    }
  </code></pre>
  <pre><code>Storing the data from firebase and adding quantity 
  Future&lt;void&gt; checkItemInCart(
      Product product, int quantity, BuildContext context) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
  
    // convert to map
    var product_str = product.toMap();
  
    // combine product with quantity
    String productWithQuantity =
        product_str.toString() + '-quantity-' + quantity.toString();
  
    // check if project exists first
    List&lt;String&gt; userCartPref = (prefs.getStringList('userCart') ?? &lt;String&gt;[]);
    ['Product-quantity-2'];
  
    /*
     update {
     check if found
     }
    */
  
    List&lt;String&gt; temp = (prefs.getStringList('userCart') ?? &lt;String&gt;[]);
    // add f
    //userCartPref ['iphone 1','laptop 3'];
    // temp ['laptop 3'];
    var foundInCart = false;
    for (var i = 0; i &lt; userCartPref.length; i++) {
      var item = userCartPref[i];
      var items = item.split('-quantity-'); //list [product,quantity]
      var old_product = items[0];
      var old_qty = items[1];
      if (old_product.contains(product.pid)) {
        foundInCart = true;
        // product exists
        // delete the current item
        temp.removeAt(i);
        // set pref to temp
        prefs.setStringList('userCart', temp);
  
        // sum the quantity 2 1
        String finalQuantity = (quantity + int.parse(old_qty)).toString();
        // create string for pref with the updated quantity
        String updatedProductWithQuantity =
            product_str.toString() + '-quantity-' + finalQuantity;
        //add item with the updated quantity iphone 2
        addItemToCart(updatedProductWithQuantity, context);
        showSnackBar(context, &quot;Quantity has been updated successfully&quot;);
  
        break;
      }
  
    
    }
    if (userCartPref.length == 0 || foundInCart == false) {
      addItemToCart(productWithQuantity, context);
      showSnackBar(context, &quot;Product added successfully to cart&quot;);
    }
  
    await getProducts();
  }
  </code></pre>
  <pre><code>Future&lt;void&gt; addItemToCart(String product, BuildContext context) async {
    // await clearPref();
    print(&quot;inside&quot;);
    SharedPreferences prefs = await SharedPreferences.getInstance();
    List&lt;String&gt; tempCartList = (prefs.getStringList('userCart') ?? &lt;String&gt;[]);
    // print(tempCartList);
    tempCartList.add(product);
    prefs.setStringList('userCart', tempCartList);
  }
  </code></pre>
  <pre><code>Future&lt;void&gt; getProducts() async {
    SharedPreferences preferences = await SharedPreferences.getInstance();
    List&lt;String&gt; tempCartList =
        (preferences.getStringList('userCart') ?? &lt;String&gt;[]);
    for (var i = 0; i &lt; tempCartList.length; i++) {
      var item = tempCartList[i];
      var items = item.split('-quantity-');
      var product_ = items[0];
      var quantity_ = items[1];
    }
  }
  </code></pre>