id is not retreived onTap from ListView.builder flutter

44 Views Asked by At

I am having trouble retrieving the id of a card on tapping. The card is the outlet card, retrieved from the firestore via streambuilder. Cards appear with no issues. However, when I tap on it the outletId value returns null. Also, debugPrint() prints nothing to console. What am I doing wrong? Thank you in advance!

 StreamBuilder(
stream: FirebaseFirestore.instance.collection('users')
    .where(widget.orderModel.type!, isEqualTo: true)
    .snapshots()
    .map(
(snapshot) => snapshot.docs
    .map((document) => OutletModel.fromJson(document.data()))
    .toList()),
builder: (_, AsyncSnapshot snaps) {
  if (!snaps.hasData) {
    return Center(
        child: Text(Languages.of(_)!.noData));
  } else {
    return ListView.builder(
        physics: const ScrollPhysics(),
        scrollDirection: Axis.vertical,
        shrinkWrap: true,
        itemCount: snaps.data.length,
        itemBuilder: (BuildContext context, int index) {
          return InkWell(
onTap: () async {
            selected == false ?
            setState(() {
              selected = true;

              outletId = snaps.data[index]['id'];
              widget.orderModel.shopId =
              snaps.data[index]['id'];
              outletName = snaps.data[index]['outletName'];
              emailS = snaps.data[index]['email'];
              phoneN = snaps.data[index]['phoneNumber'];
              widget.orderModel.customerPet =
                  widget.petModel.id;

              debugPrint(
                  'the shopId is =======> ${snaps.data[index]['id']}');
            })
            : setState((){
              selected = false;
            });
          }
          child:  selected == true ? 
Stack(
              children: [
          OutletCard(outletModel: snaps.data[index]),
                const Positioned(
                        right: 0,
          top: 0,
          child: Icon(
          Icons.check_circle_outline, color: Colors.green,
          size: 50)
          ),

          ],
          ) : OutletCard(outletModel: snaps.data[index]);  
          );     
        });
  }
}
),

and the outlet card's widget is

@override
Widget build(BuildContext context) {
SizeConfig().init(context);

double screenWidth = SizeConfig.safeBlockHorizontal! * 100;
double containerHeight = Constants.getPercentSize1(screenWidth, 28);

      return InkWell(
        child: Container(
          margin: EdgeInsets.all(
              Constants.getPercentSize1(containerHeight, 5)),
          width: double.infinity,
          height: containerHeight,
          decoration: BoxDecoration(
              color: Theme.of(context).canvasColor,
              border: Border.all(
                  width: 1,
                  color: iconColor
              ),
              borderRadius: const BorderRadius.all(
                  Radius.circular(10)
              ),
              boxShadow: [
                BoxShadow(color: shadowColor, blurRadius: 2)]
          ),
          padding: EdgeInsets.all(
              Constants.getPercentSize1(containerHeight, 7)),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              ClipRRect(
                borderRadius: const BorderRadius.all(Radius.circular(7)),
                child: SizedBox(
                  width: Constants.getPercentSize1(
                      containerHeight, 60),
                  height: Constants.getPercentSize1(
                      containerHeight, 60),
                  child: Image.network(
                    widget.outletModel.outletImage!,
                    fit: BoxFit.cover,
                  ),
                ),
              ),
              getHorizonSpace(
                  Constants.getPercentSize1(screenWidth, 3)),
              Expanded(
                flex: 1,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        getCustomText(
                            widget.outletModel.outletName!,
                            Theme.of(context).primaryColorLight,
                            1,
                            TextAlign.start,
                            FontWeight.bold,
                            15),
                        const Spacer(),
                        const Icon(Icons.star, color: Colors.amber, size:20),
                        getCustomText(
                            widget.outletModel.averageRating.toString(),
                            Theme.of(context).primaryColorLight,
                            1,
                            TextAlign.start,
                            FontWeight.bold,
                            Constants.getPercentSize1(
                                containerHeight, 13)),
                      ],
                    ),
                    Flexible(
                      child: Text(
                        widget.outletModel.outletDesc!,
                        softWrap: true, textAlign: TextAlign.start,
                          style: TextStyle(
                        color: Theme.of(context).primaryColorLight,
                        fontWeight: FontWeight.w400,
                        fontSize: 12)
                      )
                    ),
                    getSpace(Constants.getPercentSize1(
                        containerHeight, 2)),
                    ],
                ),
              )
            ],
          ),
        ),
        onDoubleTap: () {
          Get.to(() => OutletScreen(outletModel: widget.outletModel, outletId: widget.outletModel.id!));
        },
    );
}
0

There are 0 best solutions below