widgetForOfferRail static method
Widget
widgetForOfferRail({
- required Rails? item,
- required BuildContext context,
- required int currentItemIndex,
- required dynamic onCarouselPageChanged({}),
Implementation
static Widget widgetForOfferRail({
required Rails? item,
required BuildContext context,
required int currentItemIndex,
required Function({required int carouselIndex, required int railIndex})
onCarouselPageChanged,
}) {
final RailType? railType = getRailType(val: item?.type ?? "");
debugPrint("Rail type : ${railType}");
Widget widget = SizedBox();
// if (railType == RailType.GRID) {
// widget = PopularBrandWidget(
// item: item,
// onTileTap: ({required String couponId}) {
// // context.pushNamed(Routes.voucherDetail, extra: {
// // "couponId" : couponId,
// // });
// final offerBloc = context.read<OfferBloc>();
// showDialog(
// context: context,
// barrierDismissible: true,
// builder: (BuildContext dialogContext) {
// // Use BlocProvider.value to pass the existing bloc
// return BlocProvider.value(
// value: offerBloc,
// child: PurchaseVoucherWidget(couponId: couponId),
// );
// },
// );
// },
// onViewAllTap: () {
// context.pushNamed(Routes.offersViewAll);
// },
// );
// }
// else
if (railType == RailType.GROUP) {
widget = CategoriesWidget(
item: item,
onCategoryTap: (_) {},
);
}
// widget = Padding(
// padding: const EdgeInsets.only(top: 20.0),
// child: CategoriesWidget(
// item: item,
// onCategoryTap: (String categoryId) {
// context.pushNamed(
// Routes.offersViewAll,
// extra: {
// "categoryId": categoryId,
// },
// );
// },
// ),
// );
// } else if (railType == RailType.GRID_BASIC) {
// widget = Padding(
// padding: const EdgeInsets.only(top: 20.0),
// child: OfferSection(
// item: item,
// ),
// );
// } else if (railType == RailType.GRID_PREMIUM) {
// widget = Padding(
// padding: const EdgeInsets.only(top: 20.0),
// child: PremiumBrandSection(
// item: item,
// ),
// );
// }
else if (railType == RailType.STEP) {
debugPrint("Entered step rail type");
widget = Padding(
padding: EdgeInsets.only(top: 20),
child: RedeemStepsWidget(
rail: item,
));
} else if (railType == RailType.BANNER) {
widget = Container(
color: item?.data?.bgColor?.isNotEmpty == true
? Color(CommonMethod().hexToInt(hex: item?.data?.bgColor ?? ""))
: AppColors.white,
padding: EdgeInsets.fromLTRB(0, 16, 0, 24),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
Images.arrowLeft,
package: Constants.packageName,
height: 16,
width: 16,
color: AppColors.black,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Text(
item?.data?.header ?? "",
style: Styles.tsBlack3BSemiBold18(),
),
),
SvgPicture.asset(
Images.arrowRight,
package: Constants.packageName,
height: 16,
width: 16,
color: AppColors.black,
),
],
),
12.h,
CarouselSlider(
options: CarouselOptions(
autoPlay: false,
viewportFraction: 0.8,
// padEnds: false,
enlargeCenterPage: true,
clipBehavior: Clip.none,
height: 150,
// onPageChanged: (index, reason) {
// onUpdateBannerIndex(bannerCurrentIndex: index);
// },
),
items: item?.contents?.map((val) {
return GestureDetector(
onTap: () {
VoucherAnalyticsImpl.logEvent(
eventName: VoucherAnalyticsEvent.promotionalBannerClicked,
parameters: {
'sku': val.typeData?.sku ?? '',
'type': val.typeData?.type ?? '',
'cta': val.typeData?.cta ?? '',
},
);
AppDialog.showBlurDialog(
context: context,
child: MultiBlocProvider(
providers: [
BlocProvider.value(value: AppPages.offerBloc),
BlocProvider(
create: (_) => getIt<PurchaseVoucherBloc>(),
),
],
child: PurchaseVoucherView(
sku: val.typeData?.sku ?? "",
),
),
);
},
child:
// Container(color: AppColors.red,)
ImageBannerWidget(
imageUrl: val.thumbnail?.url ?? "",
),
);
}).toList(),
),
],
),
);
} else if (railType == RailType.BANNER_WITH_HEADER) {
widget = OfferSection(
item: item,
);
} else if (railType == RailType.PROMOTION) {
final List<Contents> promotions = item?.contents ?? [];
widget = Container(
color: item?.data?.bgColor?.isNotEmpty == true
? Color(CommonMethod().hexToInt(hex: item?.data?.bgColor ?? ""))
: AppColors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
child: Column(
children: [
SizedBox(
height: 500,
child: PageView.builder(
controller: PageController(
viewportFraction: 1,
),
itemCount: promotions.length,
onPageChanged: (index) {
debugPrint("On page changed");
onCarouselPageChanged(
carouselIndex: index,
railIndex: currentItemIndex,
);
},
itemBuilder: (context, index) {
final content = promotions[index];
PromotionColors? promotionColors =
content.typeData?.promotionColors;
return PromotionCardWidget(
logo: content.thumbnail?.url ?? "",
heading: content.typeData?.heading ?? "",
title: content.typeData?.title ?? "",
subTitle: content.typeData?.subTitle ?? "",
ctaText: content.typeData?.ctaText ?? "",
promoImage: content.typeData?.proImg ?? "",
primaryColor: Color(CommonMethod().hexToInt(
hex: content
.typeData?.promotionColors?.gradient?.primary ??
"")),
secondaryColor: Color(CommonMethod().hexToInt(
hex: content.typeData?.promotionColors?.gradient
?.secondary ??
"")),
headingColor: Color(
CommonMethod().hexToInt(
hex: promotionColors?.heading ?? "",
),
),
ctaBgColor: Color(CommonMethod()
.hexToInt(hex: promotionColors?.ctaBg ?? "")),
ctaTxtColor: Color(
CommonMethod().hexToInt(
hex: promotionColors?.ctaTxt ?? "",
),
),
subTitleColor: Color(
CommonMethod().hexToInt(
hex: promotionColors?.subTitle ?? "",
),
),
titleColor: Color(
CommonMethod().hexToInt(
hex: promotionColors?.title ?? "",
),
),
borderColor: promotionColors?.border == null
? AppColors.grey
: Color(
CommonMethod().hexToInt(
hex: promotionColors?.border ?? "",
),
),
onPromotionalCardTap: () {
if (content.typeData?.sku?.isNotEmpty ?? false) {
AppDialog.showBlurDialog(
context: context,
child: MultiBlocProvider(
providers: [
BlocProvider.value(value: AppPages.offerBloc),
BlocProvider(
create: (_) => getIt<PurchaseVoucherBloc>(),
),
],
child: PurchaseVoucherView(
sku: content.typeData?.sku ?? "",
),
),
);
} else if (content.typeData?.categoryName?.isNotEmpty ??
false) {
context.pushNamed(
Routes.searchView,
extra: {
"categoryId": content.typeData?.categoryName ?? "",
},
);
}
},
);
},
),
),
12.h,
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(
promotions.length,
(index) {
final isSelected = (item?.currentCarouselIndex ?? 0) == index;
return AnimatedContainer(
duration: const Duration(milliseconds: 250),
margin: const EdgeInsets.symmetric(horizontal: 4),
height: 8,
width: isSelected ? 24 : 8,
decoration: BoxDecoration(
color: isSelected
? Colors.black
: Colors.black.withOpacity(0.25),
borderRadius: BorderRadius.circular(100),
),
);
},
),
),
],
),
);
} else if (railType == RailType.EXPLORE) {
widget = Container(
height: 550,
padding: EdgeInsets.only(
top: 20,
),
child: ExploreWidget(
item: item,
),
);
} else if (railType == RailType.FEATURED) {
widget = FeaturedCategoryWidget(
item: item,
);
} else if (railType == RailType.SINGLE_BANNER) {
widget = Padding(
padding: const EdgeInsets.all(16.0),
child: GestureDetector(
onTap: () {
context.pushNamed(
Routes.searchView,
extra: {
"categoryId": "",
},
);
},
child: SingleBannerWidget(
imageUrl: item?.contents?.first.thumbnail?.url ?? "",
),
),
);
}
return widget;
// }
}