getListItem function

Widget getListItem({
  1. void onTap()?,
  2. required Widget child,
  3. bool marginHorizontal = true,
  4. bool hide = false,
  5. bool loading = false,
  6. void editOnTap()?,
  7. void deleteOnTap()?,
})

Implementation

Widget getListItem({
  void Function()? onTap,
  required Widget child,
  bool marginHorizontal = true,
  bool hide = false,
  bool loading = false,
  void Function()? editOnTap,
  void Function()? deleteOnTap,
}) {
  if (hide) return Container();
  if (loading) {
    return MahasShimmer.getShimmerListItem(
      count: 1,
      padding: MahasDimensions.getListItemPadding(),
      marginTop: 0,
    );
  }

  var appBarPadding = MahasDimensions.getAppBarPadding();
  return InkWell(
    onTap: onTap,
    child: Container(
      margin: EdgeInsets.symmetric(
        horizontal: marginHorizontal ? appBarPadding : 0,
        vertical: appBarPadding / 2,
      ),
      width: double.infinity,
      decoration: ShapeDecoration(
        shadows: MahasDimensions.getShadows(),
        color: MahasColors.whiteColor,
        shape: MahasDimensions.getShape(),
      ),
      child: ClipRect(
        child: Slidable(
          enabled: editOnTap != null || deleteOnTap != null,
          endActionPane: ActionPane(
            extentRatio: 0.35,
            motion: const DrawerMotion(),
            children: [
              if (editOnTap != null)
                Expanded(
                  child: InkWell(
                    onTap: editOnTap,
                    child: Container(
                      padding: EdgeInsets.all(
                          MahasDimensions.getHeightPercentSize(1.2)),
                      color: MahasColors.primaryColor.withOpacity(.2),
                      child: Center(
                        child: getIcon('edit', color: MahasColors.primaryColor),
                      ),
                    ),
                  ),
                ),
              if (deleteOnTap != null)
                Expanded(
                  child: InkWell(
                    onTap: deleteOnTap,
                    child: Container(
                      padding: EdgeInsets.all(
                          MahasDimensions.getHeightPercentSize(1.2)),
                      color: MahasColors.dangerColor.withOpacity(.2),
                      child: Center(
                        child:
                            getIcon('delete', color: MahasColors.dangerColor),
                      ),
                    ),
                  ),
                ),
            ],
          ),
          child: Container(
            padding: EdgeInsets.symmetric(
              horizontal: MahasDimensions.getHeightPercentSize(2.5),
              vertical: MahasDimensions.getHeightPercentSize(1.5),
            ),
            child: child,
          ),
        ),
      ),
    ),
  );
}