Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CarouselWidget extends StatefulWidget {
- const CarouselWidget({super.key});
- @override
- State<CarouselWidget> createState() => _CarouselWidgetState();
- }
- class _CarouselWidgetState extends State<CarouselWidget> {
- CarouselController carouselController = CarouselController();
- @override
- Widget build(BuildContext context) {
- Size size = MediaQuery.sizeOf(context);
- double height = size.height;
- double width = size.width;
- HabitCategoryData habitCategoryData =
- Provider.of<HabitCategoryProvider>(context).habitCategoryData;
- List<HabitCategoryData> habitCategoryDataList =
- habitCategoryDataMap.values.toList();
- int newIndex = habitCategoryDataList.indexOf(habitCategoryData);
- return Column(
- children: [
- RepaintBoundary(
- child: SizedBox(
- height: height * 0.24,
- width: width,
- child: Stack(
- alignment: Alignment.center,
- children: [
- Positioned.fill(
- child: CarouselSlider.builder(
- carouselController: carouselController,
- itemCount: habitCategoryDataMap.length,
- itemBuilder: (context, index, realIndex) {
- return CategoryCard(
- habitCategoryData: habitCategoryDataList[index]);
- },
- options: CarouselOptions(
- initialPage: newIndex,
- enlargeCenterPage: true,
- autoPlay: false,
- viewportFraction: 0.6,
- onPageChanged: (index, reason) {
- HabitCategoryData newHabitCategoryData =
- habitCategoryDataList[index];
- Provider.of<HabitCategoryProvider>(context,
- listen: false)
- .setHabitVariables(newHabitCategoryData);
- Provider.of<HabitCategoryProvider>(context,
- listen: false)
- .clearSelectedItemsList();
- },
- ),
- ),
- ),
- Positioned(
- left: 12,
- //bottom: height * 0.25 / 2,
- child: Container(
- alignment: Alignment.center,
- height: (height * 0.24) * (1 / 4),
- decoration: BoxDecoration(
- color: Colors.white.withOpacity(0.7),
- borderRadius: BorderRadius.circular(12),
- ),
- child: IconButton(
- onPressed: carouselController.previousPage,
- icon: const Icon(Icons.arrow_back_ios_rounded),
- ),
- ),
- ),
- Positioned(
- right: 12,
- //bottom: height * 0.25 / 2,
- child: Container(
- alignment: Alignment.center,
- height: (height * 0.24) * (1 / 4),
- decoration: BoxDecoration(
- color: Colors.white.withOpacity(0.7),
- borderRadius: BorderRadius.circular(12),
- ),
- child: IconButton(
- onPressed: carouselController.nextPage,
- icon: const Icon(Icons.arrow_forward_ios_rounded),
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- const SizedBox(
- height: 8,
- ),
- Text(
- habitCategoryData.title,
- style: Theme.of(context).textTheme.bodyLarge,
- ),
- ],
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement