title: flutter Error: The method '[]' was called on null. Receiver: null Tried calling: []("product")
body: <p>when I clicking on my cart icon then open my cartpage.dart in this page my data not showing  and give error but when i am using fast reload flutter page then that data is comming.
  How to solve it please help me.</p>
  <h2>error=&gt;
  The method '[]' was called on null. Receiver: null Tried calling: </h2>
  <p><a href="https://i.stack.imgur.com/KogwX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KogwX.png" alt="enter image description here" /></a></p>
  <p>This is my cartPage.dart</p>
  <pre><code>import 'dart:convert';
  
  import 'package:flutter/material.dart';
  import 'package:hospital/CartPage/components/cartCard.dart';
  import 'package:hospital/CartPage/components/priceDetailsCard.dart';
  import 'package:hospital/constant.dart';
  import 'package:hospital/customApiVariable.dart';
  import 'package:http/http.dart' as http;
  
  class Cartpage extends StatefulWidget {
    @override
    _CartpageState createState() =&gt; _CartpageState();
  }
  
  class _CartpageState extends State&lt;Cartpage&gt; {
    var response;
  
    var addToCartApi;
  
    @override
    void initState() {
  
      super.initState();
  
      fetchData();
    }
  
    fetchData() async {
      var api = Uri.parse(
          '$ecommerceBaseUrl/addToCartApi.php?a2rTokenKey=$a2rTokenKey&amp;action=addToCartList&amp;uid=${var_uid}');
  
      response = await http.get(api);
  
      print(&quot;Carousel&quot; + response.body);
      addToCartApi = jsonDecode(response.body);
      print('addToCartApi' + addToCartApi['total'].toString());
  
  
  // store in variable 
      totalOfferPrice = addToCartApi['total']['grandTotalOfferPrice'].toString();
      totalPrice = addToCartApi['total']['grandTotalPrice'].toString();
      totalPriceAfterOffer =
          addToCartApi['total']['grandTotalPriceAfterOffer'].toString();
      deliveryName = addToCartApi['total']['deliveryName'];
      deliveryCharge = addToCartApi['total']['deliveryCharge'].toString();
      total_num = addToCartApi['total']['num'].toString();
  
      setState(() {});
    }
  
    // List allItems = CartRepo().getAllCartItems();
    @override
    Widget build(BuildContext context) {
      final _media = MediaQuery.of(context).size;
      return Scaffold(
          appBar: AppBar(
            backgroundColor: kGreen,
            title: Text(&quot;My Cart&quot;),
          ),
          body: Stack(
            children: [
              Container(
                decoration: BoxDecoration(color: Color(0xFFeeeeee)),
                height: _media.height,
                width: _media.width,
              ),
              ListView(
                shrinkWrap: true,
                children: &lt;Widget&gt;[
                  CartCard(user_id: var_uid),
                  PriceDetailsCard(totalItem: addToCartApi['total']),
                  SizedBox(
                    height: 100,
                  )
                ],
              ),
              Align(
                alignment: Alignment.bottomCenter,
                child: Container(
                  width: _media.width,
                  height: _media.height * .08,
                  decoration: BoxDecoration(color: Colors.white, boxShadow: [
                    BoxShadow(color: Colors.black87, blurRadius: 5.0),
                    BoxShadow(color: Colors.white, blurRadius: 10.0),
                  ]),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: &lt;Widget&gt;[
                      Padding(
                        padding: const EdgeInsets.only(left: 10.0),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: &lt;Widget&gt;[
                            Text(
                              &quot;\u20B9 ${totalPriceAfterOffer}&quot;,
                              style: TextStyle(
                                  fontWeight: FontWeight.bold, fontSize: 20),
                            ),
                            Text(
                              &quot;View price details&quot;,
                              style: TextStyle(
                                  color: Colors.blueGrey,
                                  fontWeight: FontWeight.bold),
                            )
                          ],
                        ),
                      ),
                      Padding(
                        padding: const EdgeInsets.only(right: 10.0),
                        child: Container(
                            width: _media.width * .4,
                            child: RaisedButton(
                              onPressed: () {},
                              color: kGreen,
                              child: Text(
                                &quot;PLACE ORDER&quot;,
                                style: TextStyle(color: Colors.white),
                              ),
                            )),
                      ),
                    ],
                  ),
                ),
              )
            ],
          ));
    }
  }
  
  </code></pre>
  <p>This is CartCard.dart page</p>
  <pre><code>import 'dart:convert';
  
  import 'package:flutter/material.dart';
  // import 'package:hospital/FourthDelete/fourth_delete.dart';
  // import 'package:hospital/FourthSection/MedicineProductList/medicine_product_list.dart';
  import 'package:hospital/ProductDetailsPage/product_detailPage.dart';
  import 'package:hospital/SecondSection/Medicine/medicine_page.dart';
  import 'package:hospital/constant.dart';
  import 'package:hospital/customApiVariable.dart';
  import 'package:http/http.dart' as http;
  
  class CartCard extends StatefulWidget {
    final user_id;
  
    const CartCard({Key key, this.user_id}) : super(key: key);
    @override
    _CartCardState createState() =&gt; _CartCardState();
  }
  
  class _CartCardState extends State&lt;CartCard&gt; {
    var response;
  
    //this drinks call from api
    var cartCardApi;
  
    @override
    void initState() {
      // TODO: implement initState
      //
      super.initState();
  // for loading
      fetchData(widget.user_id);
    }
  
    fetchData(auth_uid) async {
      // var api = Uri.parse(
      //     'https://www.a2rstore.in/oceonicApi/ecommerce/v2/api/categoryApi.php?a2rTokenKey=carpet1234');
      // var api = Uri.parse('$baseUrl/productCatApi.php?a2rTokenKey=$a2rTokenKey');
      var api = Uri.parse(
          // '$ecommerceBaseUrl/addToCartApi.php?a2rTokenKey=$a2rTokenKey&amp;action=addToCartList&amp;uid=${widget.auth_uid}');
          '$ecommerceBaseUrl/addToCartApi.php?a2rTokenKey=$a2rTokenKey&amp;action=addToCartList&amp;uid=${widget.user_id}');
      // 'https://www.a2rstore.in/oceonicApi/ecommerce/v1/api/productSubCatApi.php?a2rTokenKey=a2rhos1234&amp;pcat=60c461f032f2a');
      response = await http.get(
        api,
      );
      print(&quot;cartCardApi &quot; + api.toString());
      print(&quot;cartCardbody &quot; + response.body);
  
      // in double quotes drink is key value of json
  
      cartCardApi = jsonDecode(response.body);
  
      print(&quot;cartCardApi &quot; + cartCardApi.toString());
      return cartCardApi['product'];
      // setState(() {});
    }
  
    String quantity = &quot;1&quot;;
    @override
    Widget build(BuildContext context) {
      final _media = MediaQuery.of(context).size;
      return ListView.builder(
          // itemCount: categoryApi.length.clamp(0, 3),//THis is for showed minimun length of item listview.builder flutter
          itemCount: cartCardApi['product'].length,
          scrollDirection: Axis.vertical,
          physics: ScrollPhysics(),
          shrinkWrap: true,
          itemBuilder: (context, index) {
            var cartCard = cartCardApi['product'][index];
            return Container(
              height: _media.height * .4,
              child: Card(
                color: Colors.white,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: &lt;Widget&gt;[
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: &lt;Widget&gt;[
                        Padding(
                          padding: const EdgeInsets.only(
                              left: 10.0, top: 10, bottom: 8),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: &lt;Widget&gt;[
                              Container(
                                width: _media.width * .6,
                                child: Text(
                                  // widget.item.desc,
                                  cartCard[&quot;productName&quot;],
                                  maxLines: 2,
                                  style: TextStyle(
                                      color: Colors.black,
                                      fontSize: 18,
                                      fontWeight: FontWeight.w500),
                                  overflow: TextOverflow.ellipsis,
                                ),
                              ),
                              SizedBox(
                                height: 5,
                              ),
                              Text(
                                // widget.item.quantity,
                                ' Quantity ${cartCard['orderQuantity']}',
                                style:
                                    TextStyle(color: Colors.grey, fontSize: 14),
                              ),
                              SizedBox(
                                height: 10,
                              ),
                              Row(
                                children: &lt;Widget&gt;[
                                  Text(
                                    &quot;Seller: &quot;,
                                    style: TextStyle(
                                        color: Colors.grey, fontSize: 14),
                                  ),
                                  Icon(
                                    Icons.check_circle,
                                    color: Colors.grey,
                                    size: 15,
                                  )
                                ],
                              ),
                              SizedBox(
                                height: 15,
                              ),
                              Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                crossAxisAlignment: CrossAxisAlignment.end,
                                children: &lt;Widget&gt;[
                                  Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: &lt;Widget&gt;[
                                      Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.start,
                                        children: &lt;Widget&gt;[
                                          Text(
                                            &quot;\u20B9 &quot; +
                                                cartCard[
                                                    'productPriceAfterOffer'],
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                fontSize: 23),
                                          ),
                                          Padding(
                                            padding:
                                                const EdgeInsets.only(left: 10.0),
                                            child: Text(
                                              &quot;\u20B9 &quot; +
                                                  cartCard['productRealPrice'],
                                              style: TextStyle(
                                                  color: Colors.grey,
                                                  decoration:
                                                      TextDecoration.lineThrough),
                                            ),
                                          ),
                                          SizedBox(
                                            width: 5,
                                          ),
                                          Text(
                                            '40' + &quot;%off&quot;,
                                            style: TextStyle(
                                                color: Colors.green,
                                                fontSize: 13,
                                                fontWeight: FontWeight.w600),
                                          )
                                        ],
                                      ),
                                      SizedBox(
                                        height: 10,
                                      ),
                                      Text(
                                        &quot;2 offers available&quot;,
                                        style: TextStyle(
                                            color: Colors.green,
                                            fontSize: 13,
                                            fontWeight: FontWeight.w600),
                                      )
                                    ],
                                  )
                                ],
                              )
                            ],
                          ),
                        ),
                        Padding(
                          padding: const EdgeInsets.only(
                              top: 10.0, right: 8, bottom: 8),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: &lt;Widget&gt;[
                              Container(
                                color: Colors.white,
                                child: Row(
                                  children: &lt;Widget&gt;[
                                    Container(
                                      width: _media.width * .3,
                                      height: _media.height * .2,
                                      child: Image.network(
                                        // 'https://media.gettyimages.com/photos/woman-using-meal-delivery-service-through-mobile-app-picture-id1160735344?k=6&amp;m=1160735344&amp;s=612x612&amp;w=0&amp;h=tYEeckvNDyAoyUEfUeCii_29p_pBum_BVHKiUrGbjYY=',
                                        cartCard['pImgImg'],
                                        fit: BoxFit.cover,
                                      ),
                                    )
                                  ],
                                ),
                              ),
                              Row(
                                children: &lt;Widget&gt;[
                                  Text(
                                    &quot;Qty:&quot;,
                                    style: TextStyle(fontWeight: FontWeight.bold),
                                  ),
                                  SizedBox(
                                    width: 10,
                                  ),
                                  DropdownButton&lt;String&gt;(
                                    value: quantity,
                                    items: &lt;String&gt;[&quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;]
                                        .map((String value) =&gt;
                                            DropdownMenuItem&lt;String&gt;(
                                                value: value, child: Text(value)))
                                        .toList(),
                                    onChanged: (_value) {
                                      setState(() {
                                        quantity = _value;
                                      });
                                    },
                                  )
                                ],
                              ),
                            ],
                          ),
                        )
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: &lt;Widget&gt;[
                        Container(
                          height: _media.height * .08,
                          width: _media.width * .4875,
                          child: RaisedButton(
                            onPressed: () {},
                            color: Colors.white,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: &lt;Widget&gt;[
                                Icon(
                                  Icons.favorite,
                                  size: 15,
                                  color: Colors.grey,
                                ),
                                SizedBox(
                                  width: 5,
                                ),
                                Text(
                                  &quot;SAVE FOR LATER&quot;,
                                  style: TextStyle(fontSize: 15),
                                )
                              ],
                            ),
                          ),
                        ),
                        Container(
                          height: _media.height * .08,
                          width: _media.width * .4875,
                          child: RaisedButton(
                            onPressed: () {},
                            color: Colors.white,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: &lt;Widget&gt;[
                                Icon(
                                  Icons.delete,
                                  size: 15,
                                  color: Colors.grey,
                                ),
                                SizedBox(
                                  width: 5,
                                ),
                                Text(
                                  &quot;REMOVE&quot;,
                                  style: TextStyle(fontSize: 15),
                                )
                              ],
                            ),
                          ),
                        ),
                      ],
                    )
                  ],
                ),
              ),
            );
          });
    }
  }
  
  </code></pre>
  <h2>This is my json data</h2>
  <pre><code>{
    &quot;product&quot;: [
      {
        &quot;plistId&quot;: &quot;60c71ed46839f&quot;,
        &quot;plistPriceId&quot;: &quot;&quot;,
        &quot;uid&quot;: &quot;60daaedd3b9f8751161&quot;,
        &quot;orderQuantity&quot;: &quot;1&quot;,
        &quot;date&quot;: &quot;2021-07-06&quot;,
        &quot;productName&quot;: &quot;MUKTI CHURNA&quot;,
        &quot;productCode&quot;: &quot;499&quot;,
        &quot;productlink&quot;: &quot;detail.php?pListName=MUKTI CHURNA&amp;plistId=60c71ed46839f&quot;,
        &quot;productRealPrice&quot;: &quot;1112&quot;,
        &quot;productPriceAfterOffer&quot;: 1110,
        &quot;productOfferAmountMulOrdrQuantity&quot;: 0,
        &quot;quantity&quot;: &quot;1 p&quot;,
        &quot;pImgImg&quot;: &quot;http:\/\/a2rstore.com\/inventory\/images\/product_images\/product-Mukti-Churan-600x600.jpg&quot;,
        &quot;subTotalRealPrice&quot;: 1110,
        &quot;subTotalofferPrice&quot;: 0,
        &quot;subTotalPriceAfterOffer&quot;: 1110
      },
      {
        &quot;plistId&quot;: &quot;60cacee2ee4ff&quot;,
        &quot;plistPriceId&quot;: &quot;&quot;,
        &quot;uid&quot;: &quot;60daaedd3b9f8751161&quot;,
        &quot;orderQuantity&quot;: &quot;1&quot;,
        &quot;date&quot;: &quot;2021-07-06&quot;,
        &quot;productName&quot;: &quot; PAIN CALM OIL&quot;,
        &quot;productCode&quot;: &quot;504&quot;,
        &quot;productlink&quot;: &quot;detail.php?pListName= PAIN CALM OIL&amp;plistId=60cacee2ee4ff&quot;,
        &quot;productRealPrice&quot;: &quot;123&quot;,
        &quot;productPriceAfterOffer&quot;: &quot;123&quot;,
        &quot;productOfferAmountMulOrdrQuantity&quot;: 0,
        &quot;quantity&quot;: &quot;1 p&quot;,
        &quot;pImgImg&quot;: &quot;http:\/\/a2rstore.com\/inventory\/images\/product_images\/product-Oil-pulling-ff-600x600.jpg&quot;,
        &quot;subTotalRealPrice&quot;: 123,
        &quot;subTotalofferPrice&quot;: 0,
        &quot;subTotalPriceAfterOffer&quot;: 123
      },
      {
        &quot;plistId&quot;: &quot;60cacee2ee4ff&quot;,
        &quot;plistPriceId&quot;: &quot;&quot;,
        &quot;uid&quot;: &quot;60daaedd3b9f8751161&quot;,
        &quot;orderQuantity&quot;: &quot;3&quot;,
        &quot;date&quot;: &quot;2021-07-06&quot;,
        &quot;productName&quot;: &quot; PAIN CALM OIL&quot;,
        &quot;productCode&quot;: &quot;504&quot;,
        &quot;productlink&quot;: &quot;detail.php?pListName= PAIN CALM OIL&amp;plistId=60cacee2ee4ff&quot;,
        &quot;productRealPrice&quot;: &quot;123&quot;,
        &quot;productPriceAfterOffer&quot;: &quot;123&quot;,
        &quot;productOfferAmountMulOrdrQuantity&quot;: 0,
        &quot;quantity&quot;: &quot;1 p&quot;,
        &quot;pImgImg&quot;: &quot;http:\/\/a2rstore.com\/inventory\/images\/product_images\/product-Oil-pulling-ff-600x600.jpg&quot;,
        &quot;subTotalRealPrice&quot;: 369,
        &quot;subTotalofferPrice&quot;: 0,
        &quot;subTotalPriceAfterOffer&quot;: 369
      },
      {
        &quot;plistId&quot;: &quot;60cacee2ee4ff&quot;,
        &quot;plistPriceId&quot;: &quot;&quot;,
        &quot;uid&quot;: &quot;60daaedd3b9f8751161&quot;,
        &quot;orderQuantity&quot;: &quot;3&quot;,
        &quot;date&quot;: &quot;2021-07-06&quot;,
        &quot;productName&quot;: &quot; PAIN CALM OIL&quot;,
        &quot;productCode&quot;: &quot;504&quot;,
        &quot;productlink&quot;: &quot;detail.php?pListName= PAIN CALM OIL&amp;plistId=60cacee2ee4ff&quot;,
        &quot;productRealPrice&quot;: &quot;123&quot;,
        &quot;productPriceAfterOffer&quot;: &quot;123&quot;,
        &quot;productOfferAmountMulOrdrQuantity&quot;: 0,
        &quot;quantity&quot;: &quot;1 p&quot;,
        &quot;pImgImg&quot;: &quot;http:\/\/a2rstore.com\/inventory\/images\/product_images\/product-Oil-pulling-ff-600x600.jpg&quot;,
        &quot;subTotalRealPrice&quot;: 369,
        &quot;subTotalofferPrice&quot;: 0,
        &quot;subTotalPriceAfterOffer&quot;: 369
      },
      {
        &quot;plistId&quot;: &quot;60cacee2ee4ff&quot;,
        &quot;plistPriceId&quot;: &quot;&quot;,
        &quot;uid&quot;: &quot;60daaedd3b9f8751161&quot;,
        &quot;orderQuantity&quot;: &quot;1&quot;,
        &quot;date&quot;: &quot;2021-07-06&quot;,
        &quot;productName&quot;: &quot; PAIN CALM OIL&quot;,
        &quot;productCode&quot;: &quot;504&quot;,
        &quot;productlink&quot;: &quot;detail.php?pListName= PAIN CALM OIL&amp;plistId=60cacee2ee4ff&quot;,
        &quot;productRealPrice&quot;: &quot;123&quot;,
        &quot;productPriceAfterOffer&quot;: &quot;123&quot;,
        &quot;productOfferAmountMulOrdrQuantity&quot;: 0,
        &quot;quantity&quot;: &quot;1 p&quot;,
        &quot;pImgImg&quot;: &quot;http:\/\/a2rstore.com\/inventory\/images\/product_images\/product-Oil-pulling-ff-600x600.jpg&quot;,
        &quot;subTotalRealPrice&quot;: 123,
        &quot;subTotalofferPrice&quot;: 0,
        &quot;subTotalPriceAfterOffer&quot;: 123
      },
      {
        &quot;plistId&quot;: &quot;60cacee2ee4ff&quot;,
        &quot;plistPriceId&quot;: &quot;&quot;,
        &quot;uid&quot;: &quot;60daaedd3b9f8751161&quot;,
        &quot;orderQuantity&quot;: &quot;1&quot;,
        &quot;date&quot;: &quot;2021-07-06&quot;,
        &quot;productName&quot;: &quot; PAIN CALM OIL&quot;,
        &quot;productCode&quot;: &quot;504&quot;,
        &quot;productlink&quot;: &quot;detail.php?pListName= PAIN CALM OIL&amp;plistId=60cacee2ee4ff&quot;,
        &quot;productRealPrice&quot;: &quot;123&quot;,
        &quot;productPriceAfterOffer&quot;: &quot;123&quot;,
        &quot;productOfferAmountMulOrdrQuantity&quot;: 0,
        &quot;quantity&quot;: &quot;1 p&quot;,
        &quot;pImgImg&quot;: &quot;http:\/\/a2rstore.com\/inventory\/images\/product_images\/product-Oil-pulling-ff-600x600.jpg&quot;,
        &quot;subTotalRealPrice&quot;: 123,
        &quot;subTotalofferPrice&quot;: 0,
        &quot;subTotalPriceAfterOffer&quot;: 123
      }
    ],
    &quot;total&quot;: {
      &quot;grandTotalOfferPrice&quot;: 0,
      &quot;grandTotalPrice&quot;: 123,
      &quot;grandTotalPriceAfterOffer&quot;: 123,
      &quot;deliveryName&quot;: &quot;Shipping Charge&quot;,
      &quot;deliveryCharge&quot;: &quot;Free&quot;,
      &quot;num&quot;: 6
    }
  }
  </code></pre>