homeBody method

Widget homeBody()

Implementation

Widget homeBody() {
  // print(result[i]["tiers"].length);
  // print("dataaaaa22");
  if (!isLoaded) {
    return const CircularProgressIndicator();
  } else {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Visibility(
                  visible: dummy["subscriptions"].length == 1 ||
                          i > 0 == dummy["subscriptions"].length - 1
                      ? false
                      : true,
                  child: Column(
                    children: [
                      IconButton(
                          onPressed: i > 0 && i > 0
                              ? () {
                                  selected = 0;
                                  setState(() {
                                    buttonenabled = true;
                                    i--;
                                  });
                                }
                              : null,
                          icon: const Icon(Icons.arrow_back_ios)),
                    ],
                  )),
              Expanded(
                  child: Container(
                      height: result[i]["tiers"].length > 4 ? 400 : 220,
                      // height:320,
                      child: Center(
                        child: GridView.builder(
                            itemCount: result.isNotEmpty
                                ? result[i]["tiers"].length
                                : 0,
                            gridDelegate:
                                const SliverGridDelegateWithFixedCrossAxisCount(
                                    crossAxisCount: 2,
                                    mainAxisSpacing: 8,
                                    crossAxisSpacing: 8,
                                    childAspectRatio: 1.6),
                            itemBuilder: (context, index) {
                              print(
                                  '-----basePrice---${result[i]['tiers'][index]}');
                              var basePrice =
                                  result[i]["tiers"][index]["basePrice"];
                              String percent = '';

                              if (basePrice != 0) {
                                percent = (100 -
                                            ((result[i]["tiers"][index]
                                                        ["price"] /
                                                    basePrice) *
                                                100))
                                        .toStringAsFixed(0) +
                                    "% off";
                              }
                              return InkWell(
                                onTap: () {
                                  setState(() {
                                    selected = index;
                                    // isPressed = !isPressed;
                                  });
                                },
                                // child: Align(
                                //   alignment: Alignment.center,

                                child: Padding(
                                  padding: const EdgeInsets.all(0.0),
                                  child: Container(
                                    //  height:result[i]["tiers"].length>4? 330:220,
                                    //    alignment: Alignment.center,
                                    decoration: BoxDecoration(
                                      //  color: Colors.red,
                                      border: Border.all(
                                        // color: Colors.black,
                                        color: selected == index
                                            // ? Colors.red
                                            ? Color.fromRGBO(171, 58, 53, 1.0)
                                            : Color.fromRGBO(
                                                221, 221, 221, 1.0),
                                        width: 2,
                                      ),
                                      borderRadius: BorderRadius.circular(10),
                                    ),
                                    child: Padding(
                                      padding: const EdgeInsets.symmetric(
                                          horizontal: 10, vertical: 5),
                                      child: Center(
                                        child: Column(
                                          mainAxisAlignment:
                                              MainAxisAlignment.center,
                                          crossAxisAlignment:
                                              CrossAxisAlignment.center,
                                          children: [
                                            Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.center,
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.center,
                                              children: [
                                                Text(
                                                  result[i]["tiers"][index][
                                                                  "basePrice"]
                                                              .toString() ==
                                                          "0"
                                                      ? ""
                                                      : "₹" +
                                                          result[i]["tiers"]
                                                                      [index][
                                                                  "basePrice"]
                                                              .toString() +
                                                          " ",
                                                  style: TextStyle(
                                                      decoration:
                                                          TextDecoration
                                                              .lineThrough,
                                                      fontSize: 15,
                                                      color: selected == index
                                                          ? Colors.grey
                                                          : Colors.grey),
                                                ),

                                                // result[i]!=null&& result[i]["tiers"][index]["basePrice"] == null,

                                                if (result[i]['tiers'][index]
                                                        ['basePrice'] !=
                                                    0)
                                                  Text(
                                                    //      result[i]!=null)!&& result[i]["tiers"] == null
                                                    percent.toString(),

                                                    style: TextStyle(
                                                      color: Colors.red,
                                                    ),
                                                  ),
                                              ],
                                            ),
                                            Text(
                                              "₹" +
                                                  result[i]["tiers"][index]
                                                          ["price"]
                                                      .toString() +
                                                  ".00",
                                              style: TextStyle(
                                                  fontSize: 20,
                                                  fontWeight: FontWeight.bold,
                                                  color: selected == index
                                                      ? Colors.black
                                                      : Colors.black),
                                            ),
                                            Text(
                                              result[i]["tiers"][index]
                                                          ["duration"]
                                                      .toString() +
                                                  " month",
                                              style: TextStyle(
                                                  fontSize: 17,
                                                  color: selected == index
                                                      ? Colors.black
                                                      : Colors.black),
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                                // ),
                              );
                            }),
                      ))),
              Visibility(
                  visible: dummy["subscriptions"].length == 1 ||
                          i == dummy["subscriptions"].length - 1
                      ? false
                      : true,
                  child: Column(
                    children: [
                      IconButton(
                          onPressed: i < dummy["subscriptions"].length - 1 &&
                                  i != dummy["subscriptions"].length
                              ? () {
                                  setState(() {
                                    selected = 0;
                                    print(dummy['subscriptions']);
                                    print('--------');
                                    print(i);
                                    buttonenabled = false;
                                    i++;
                                  });
                                }
                              : null,
                          icon: const Icon(Icons.arrow_forward_ios)),
                    ],
                  )),
            ],
          ),
          //-----------------------------------------------------------------------

          const Text(
            "Benefits: You will Get",
            textAlign: TextAlign.center,
            style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
          ),

          const SizedBox(
            height: 10,
          ),

          Container(
            child: SizedBox(child: BulletMark()),
          ),

          const SizedBox(
            height: 25,
          ),

          result[i] != null && result[i]["freeTrial"]["duration"] == null
              ? SizedBox()
              : Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Checkbox(
                      value: isWoman,
                      checkColor: Colors.white,
                      activeColor: Color.fromRGBO(162, 32, 38, 1.0),
                      onChanged: (value) {
                        setState(() {
                          isWoman = value!;
                        });
                      },
                    ),
                    // result[i]!=null&& result[i]["tiers"][index]["basePrice"] == null,
                    Text(
                        "Start your ${result[i]["freeTrial"]["duration"].toString()}-days",
                        style: const TextStyle(
                            fontSize: 16, fontWeight: FontWeight.bold),
                        textAlign: TextAlign.center),
                    Text(
                      " Free",
                      style: const TextStyle(
                          fontSize: 16,
                          color: Color.fromRGBO(162, 32, 38, 1.0),
                          fontWeight: FontWeight.bold),
                    ),
                    Text(
                      " Trail",
                      style: const TextStyle(
                          fontSize: 16, fontWeight: FontWeight.bold),
                    ),
                  ],
                )

          //----------------------------------------------------------------------
        ],
      ),
    );
  }
}