### Configure Installation Bundle Directory Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/CMakeLists.txt Sets up the installation prefix and the directory for the application bundle. It ensures a clean bundle directory on each installation. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Carousel Slider Controller Setup Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/README.md Example of setting up and using a `CarouselSliderController` to manually control the carousel's page transitions. This requires defining a controller instance and passing it to the widget. ```dart class CarouselDemo extends StatelessWidget { CarouselSliderController buttonCarouselController = CarouselSliderController(); @override Widget build(BuildContext context) => Column( children: [ CarouselSlider( items: child, carouselController: buttonCarouselController, options: CarouselOptions( autoPlay: false, enlargeCenterPage: true, viewportFraction: 0.9, aspectRatio: 2.0, initialPage: 2, ), ), RaisedButton( onPressed: () => buttonCarouselController.nextPage( duration: Duration(milliseconds: 300), curve: Curves.linear), child: Text('→'), ) ] ); } ``` -------------------------------- ### Install Application Components Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/CMakeLists.txt Installs the main executable, ICU data, Flutter library, and any bundled plugin libraries into the application bundle. These steps ensure all necessary files are present for the application to run. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/CMakeLists.txt Installs the Flutter assets directory into the application bundle. It ensures assets are up-to-date by removing and re-copying them. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install AOT Library Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library for non-Debug builds. This is an optimization for release and profile builds. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Find and link system-level dependencies Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/flutter/CMakeLists.txt This section finds required system libraries using PkgConfig and makes them available for linking. Ensure that `pkg-config` is installed and the development files for `gtk+-3.0`, `glib-2.0`, `gio-2.0`, `blkid`, and `liblzma` are present. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) pkg_check_modules(BLKID REQUIRED IMPORTED_TARGET blkid) pkg_check_modules(LZMA REQUIRED IMPORTED_TARGET liblzma) ``` -------------------------------- ### Fullscreen Carousel Configuration Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Sets up a carousel to fill the entire screen by using `viewportFraction: 1.0`, `enlargeCenterPage: false`, and `MediaQuery` to get screen dimensions. Includes auto-play. ```dart Builder( builder: (context) { final double screenHeight = MediaQuery.of(context).size.height; return CarouselSlider( options: CarouselOptions( height: screenHeight, viewportFraction: 1.0, enlargeCenterPage: false, autoPlay: true, ), items: imgUrls.map((url) => Image.network(url, fit: BoxFit.cover, width: double.infinity), ).toList(), ); }, ) ``` -------------------------------- ### Basic Carousel Slider Usage Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/README.md A basic example of how to implement a carousel slider with a list of items. Ensure you have the necessary imports and widgets set up. ```dart CarouselSlider( options: CarouselOptions(height: 400.0), items: [1,2,3,4,5].map((i) { return Builder( builder: (BuildContext context) { return Container( width: MediaQuery.of(context).size.width, margin: EdgeInsets.symmetric(horizontal: 5.0), decoration: BoxDecoration( color: Colors.amber ), child: Text('text $i', style: TextStyle(fontSize: 16.0),) ); }, ); }).toList(), ) ``` -------------------------------- ### Set Minimum CMake Version and Project Name Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/CMakeLists.txt Specifies the minimum required CMake version and defines the project name. This is a standard starting point for any CMake project. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) ``` -------------------------------- ### Product Gallery with CarouselSliderController Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Example of integrating CarouselSliderController to manage carousel navigation programmatically. This includes handling page changes and using navigation buttons. ```dart class ProductGallery extends StatefulWidget { @override State createState() => _ProductGalleryState(); } class _ProductGalleryState extends State { final CarouselSliderController _controller = CarouselSliderController(); int _currentIndex = 0; final List _images = [ 'https://example.com/img1.jpg', 'https://example.com/img2.jpg', 'https://example.com/img3.jpg', ]; @override Widget build(BuildContext context) { return Column( children: [ CarouselSlider( carouselController: _controller, options: CarouselOptions( height: 250.0, enableInfiniteScroll: false, enlargeCenterPage: true, onPageChanged: (index, reason) => setState(() => _currentIndex = index), ), items: _images.map((url) => Image.network(url, fit: BoxFit.cover), ).toList(), ), // Dot indicators Row( mainAxisAlignment: MainAxisAlignment.center, children: _images.asMap().entries.map((entry) { return GestureDetector( onTap: () => _controller.animateToPage(entry.key), child: Container( width: 10, height: 10, margin: EdgeInsets.symmetric(horizontal: 4, vertical: 8), decoration: BoxDecoration( shape: BoxShape.circle, color: _currentIndex == entry.key ? Colors.blue : Colors.grey, ), ), ); }).toList(), ), // Navigation buttons Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ ElevatedButton( onPressed: () => _controller.previousPage( duration: Duration(milliseconds: 400), curve: Curves.easeInOut, ), child: Text('← Prev'), ), ElevatedButton( onPressed: () => _controller.nextPage( duration: Duration(milliseconds: 400), curve: Curves.easeInOut, ), child: Text('Next →'), ), ElevatedButton( onPressed: () => _controller.jumpToPage(0), child: Text('Reset'), ), ], ), ], ); } } ``` -------------------------------- ### CarouselSliderController.startAutoPlay / stopAutoPlay Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Programmatically start or stop the auto-play timer at runtime. These methods are useful for controlling the carousel's automatic scrolling behavior based on user interaction or application state. ```APIDOC ## CarouselSliderController.startAutoPlay / stopAutoPlay ### Description Programmatically start or stop the auto-play timer at runtime. ### Method ```dart // Pause auto-play when an overlay is shown _controller.stopAutoPlay(); // Resume auto-play when the overlay is dismissed _controller.startAutoPlay(); ``` ``` -------------------------------- ### Include Flutter and System Dependencies Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/CMakeLists.txt Includes the Flutter build rules and finds system libraries like GTK using PkgConfig. This sets up the project to use Flutter and external C libraries. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Initialize CarouselSlider with Options Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/CHANGELOG.md Demonstrates how to initialize CarouselSlider by passing options to CarouselOptions. Previously, all options were passed directly to CarouselSlider. ```dart CarouselSlider( CarouselOptions(height: 400.0), items: [1,2,3,4,5].map((i) { return Builder( builder: (BuildContext context) { return Container( width: MediaQuery.of(context).size.width, margin: EdgeInsets.symmetric(horizontal: 5.0), decoration: BoxDecoration( color: Colors.amber ), child: Text('text $i', style: TextStyle(fontSize: 16.0),) ); }, ); }).toList(), ) ``` -------------------------------- ### Build Flutter Application for iOS or Android Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/README.md Commands to build the Flutter application for iOS or Android platforms. ```bash flutter build ios # or flutter build apk ``` -------------------------------- ### Run Flutter Application Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/README.md Use this command to run the Flutter application during development. ```bash flutter run ``` -------------------------------- ### Set Runtime Output Directory Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/CMakeLists.txt Configures the output directory for the executable to a specific subdirectory. This is done to ensure correct resource loading when the application is bundled. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Define Binary and Application IDs Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/CMakeLists.txt Sets the name of the executable binary and the unique application identifier. These are crucial for building and packaging the application. ```cmake set(BINARY_NAME "example") set(APPLICATION_ID "com.example.example") ``` -------------------------------- ### Configure Flutter library and headers Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/flutter/CMakeLists.txt Defines the Flutter library path and includes necessary header files. The `flutter` target is set as an INTERFACE library, meaning it provides interface information to other targets that link to it. Ensure the `ephemeral` directory contains the generated configuration and library files. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO PkgConfig::BLKID PkgConfig::LZMA ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Carousel Slider with Options Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/README.md Demonstrates configuring the carousel slider with various options such as aspect ratio, autoplay, and page change callbacks. Note that `height` overrides `aspectRatio`. ```dart CarouselSlider( items: items, options: CarouselOptions( height: 400, aspectRatio: 16/9, viewportFraction: 0.8, initialPage: 0, enableInfiniteScroll: true, reverse: false, autoPlay: true, autoPlayInterval: Duration(seconds: 3), autoPlayAnimationDuration: Duration(milliseconds: 800), autoPlayCurve: Curves.fastOutSlowIn, enlargeCenterPage: true, enlargeFactor: 0.3, onPageChanged: callbackFunction, scrollDirection: Axis.horizontal, ) ) ``` -------------------------------- ### Create CarouselSlider with Default Constructor Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Use the default `CarouselSlider` constructor for small, static lists where all items can be loaded into memory. Requires `items` and `options`. ```dart CarouselSlider( options: CarouselOptions( height: 200.0, autoPlay: true, autoPlayInterval: Duration(seconds: 3), autoPlayAnimationDuration: Duration(milliseconds: 800), autoPlayCurve: Curves.fastOutSlowIn, enlargeCenterPage: true, enlargeFactor: 0.3, viewportFraction: 0.8, ), items: ['Flutter', 'Dart', 'Mobile', 'Web', 'Desktop'].map((label) { return Builder( builder: (BuildContext context) { return Container( width: MediaQuery.of(context).size.width, margin: EdgeInsets.symmetric(horizontal: 5.0), decoration: BoxDecoration( color: Colors.blueAccent, borderRadius: BorderRadius.circular(8.0), ), child: Center( child: Text( label, style: TextStyle(fontSize: 20.0, color: Colors.white), ), ), ); }, ); }).toList(), ) ``` -------------------------------- ### Configure Flutter Windows Executable Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/windows/runner/CMakeLists.txt Defines the main executable for the Windows runner, listing all necessary source files and resources. It also applies standard build settings and links required libraries. ```cmake cmake_minimum_required(VERSION 3.15) project(runner LANGUAGES CXX) add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "run_loop.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) apply_standard_settings(${BINARY_NAME}) target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Define list_prepend function for CMake < 3.10 Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/flutter/CMakeLists.txt This function prepends a prefix to each element in a list. It is used as a workaround for older CMake versions that do not support `list(TRANSFORM ... PREPEND ...)`. Ensure the list name and prefix are correctly provided. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Custom command for Flutter tool backend Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/flutter/CMakeLists.txt This custom command invokes the Flutter tool backend script to generate necessary build artifacts like the Flutter library and headers. The `_phony_` target is used to ensure the command runs on every build, as direct input/output tracking for the Flutter tool is not yet fully supported. Ensure `FLUTTER_TOOL_ENVIRONMENT` and `FLUTTER_ROOT` are correctly set. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" linux-x64 ${CMAKE_BUILD_TYPE} VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Image Prefetching with Builder Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Pre-caches images using `precacheImage` in `initState` before serving them through `CarouselSlider.builder`. This improves the loading experience for images in the carousel. ```dart class PrefetchCarousel extends StatefulWidget { @override State createState() => _PrefetchCarouselState(); } class _PrefetchCarouselState extends State { final List imageUrls = [ 'https://example.com/photo1.jpg', 'https://example.com/photo2.jpg', 'https://example.com/photo3.jpg', ]; @override void initState() { super.initState(); WidgetsBinding.instance.addPostFrameCallback((_) { for (final url in imageUrls) { precacheImage(NetworkImage(url), context); } }); } @override Widget build(BuildContext context) { return CarouselSlider.builder( itemCount: imageUrls.length, options: CarouselOptions( autoPlay: true, aspectRatio: 2.0, enlargeCenterPage: true, ), itemBuilder: (context, index, realIdx) => Image.network( imageUrls[index], fit: BoxFit.cover, width: double.infinity, ), ); } } ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/CMakeLists.txt A function to apply common compilation features and options to a target, including C++ standard, warning levels, optimization, and NDEBUG definition. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Define Executable Target Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/CMakeLists.txt Defines the main executable target, listing its source files and applying standard settings. It also links against the Flutter library and GTK. ```cmake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) apply_standard_settings(${BINARY_NAME}) target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Configure Build Type Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/CMakeLists.txt Sets the default build type (Debug, Profile, Release) if not already specified. This influences compilation and optimization settings. ```cmake if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### Include Generated Plugin CMake Rules Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/linux/CMakeLists.txt Includes the CMake script that handles the building and registration of plugins. This is essential for integrating third-party Flutter plugins. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Create CarouselSlider with Builder Constructor Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Use the `CarouselSlider.builder` constructor to lazily build carousel items, which is memory-efficient for large lists. Requires `itemCount`, `itemBuilder`, and `options`. ```dart CarouselSlider.builder( itemCount: 50, options: CarouselOptions( aspectRatio: 16 / 9, enlargeCenterPage: true, autoPlay: true, autoPlayInterval: Duration(seconds: 4), ), itemBuilder: (BuildContext context, int itemIndex, int pageViewIndex) { return Container( margin: EdgeInsets.all(6.0), decoration: BoxDecoration( borderRadius: BorderRadius.circular(8.0), color: Colors.primaries[itemIndex % Colors.primaries.length], ), child: Center( child: Text( 'Slide $itemIndex', style: TextStyle(color: Colors.white, fontSize: 18.0), ), ), ); }, ) ``` -------------------------------- ### Configure Carousel Behavior with CarouselOptions Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Use CarouselOptions to control dimensions, scroll behavior, auto-play, and callbacks. Set explicit height or aspect ratio for dimensions. Configure auto-play settings and enlargement strategies. ```dart CarouselOptions( // Dimensions — height overrides aspectRatio if both are set height: 300.0, // explicit height in logical pixels aspectRatio: 16 / 9, // used when height is null (default: 16/9) viewportFraction: 0.85, // fraction of viewport each slide occupies (default: 0.8) // Scroll behaviour initialPage: 0, // first visible page index enableInfiniteScroll: true, // loop infinitely (default: true) animateToClosest: true, // animate to the closest occurrence when looping reverse: false, // reverse scroll direction scrollDirection: Axis.horizontal, // or Axis.vertical scrollPhysics: BouncingScrollPhysics(), pageSnapping: true, // snap to page boundaries // Auto-play autoPlay: true, autoPlayInterval: Duration(seconds: 3), autoPlayAnimationDuration: Duration(milliseconds: 600), autoPlayCurve: Curves.easeInOut, pauseAutoPlayOnTouch: true, // pause while user is touching pauseAutoPlayOnManualNavigate: true, // pause during controller navigation pauseAutoPlayInFiniteScroll: false, // pause at last item (non-infinite mode) // Center-page enlargement enlargeCenterPage: true, enlargeStrategy: CenterPageEnlargeStrategy.scale, // scale | height | zoom enlargeFactor: 0.3, // how much side pages are scaled down (0.0–1.0) // Layout extras disableCenter: false, // remove Center wrapper from each slide padEnds: true, // pad list ends so first/last slide centers clipBehavior: Clip.hardEdge, // Storage pageViewKey: PageStorageKey('my_carousel'), // preserve scroll position // Callbacks onPageChanged: (int index, CarouselPageChangedReason reason) { // reason: CarouselPageChangedReason.timed | .manual | .controller print('Moved to page $index via $reason'); }, onScrolled: (double? position) { print('Scroll position: $position'); }, ) ``` -------------------------------- ### Carousel Slider Controller Methods Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/README.md Demonstrates the usage of `CarouselSliderController` methods for programmatic control of the carousel. Available methods include `nextPage`, `previousPage`, `jumpToPage`, and `animateToPage`. ```dart buttonCarouselController.nextPage({ Duration duration, Curve curve = Curves.ease, }); ``` ```dart buttonCarouselController.previousPage({ Duration duration, Curve curve = Curves.ease, }); ``` ```dart buttonCarouselController.jumpToPage(int page); ``` ```dart buttonCarouselController.animateToPage(int page, { Duration duration, Curve curve = Curves.ease, }); ``` -------------------------------- ### CarouselSliderController.startAutoPlay / stopAutoPlay Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Programmatically control the auto-play feature of the carousel. Use `stopAutoPlay` to pause and `startAutoPlay` to resume. ```dart // Pause auto-play when an overlay is shown _controller.stopAutoPlay(); // Resume auto-play when the overlay is dismissed _controller.startAutoPlay(); ``` -------------------------------- ### Import Carousel Slider Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/README.md Import the carousel slider package into your Dart file. ```dart import 'package:carousel_slider/carousel_slider.dart'; ``` -------------------------------- ### CarouselSliderController.jumpToPage Instant Navigation Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Jumps instantly to a specific page index without any animation. Useful for resetting or navigating directly to a known page. ```dart _controller.jumpToPage(2); // jump to third item immediately ``` -------------------------------- ### Center Page Height Enlarge Strategy Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Employs the height strategy for a height-only change on the center page, offering better performance than scale transforms. Ensure `enlargeCenterPage` is true. ```dart CarouselSlider( options: CarouselOptions( aspectRatio: 2.0, enlargeCenterPage: true, enlargeStrategy: CenterPageEnlargeStrategy.height, autoPlay: true, ), items: myWidgets, ) ``` -------------------------------- ### CarouselSliderController.animateToPage Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Animates to the specified logical page index. It respects the `animateToClosest` option to choose the shortest path when infinite scroll is enabled. ```APIDOC ## CarouselSliderController.animateToPage ### Description Animates to the specified logical page index; respects `animateToClosest` to choose the shortest path when infinite scroll is enabled. ### Method ```dart await _controller.animateToPage( 4, duration: Duration(milliseconds: 500), curve: Curves.easeInOut, ); ``` ``` -------------------------------- ### Multiple Items Per Slide with Builder Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Displays multiple items within a single slide by using `CarouselSlider.builder` with `viewportFraction: 1.0` and laying out items using a `Row`. Ensure `enlargeCenterPage` is false for this layout. ```dart final List images = [/* 6 image URLs */]; CarouselSlider.builder( options: CarouselOptions( aspectRatio: 2.0, viewportFraction: 1.0, enlargeCenterPage: false, ), itemCount: (images.length / 2).ceil(), itemBuilder: (context, index, realIdx) { final int first = index * 2; final int second = first + 1; return Row( children: [first, second] .where((i) => i < images.length) .map((i) => Expanded( child: Container( margin: EdgeInsets.symmetric(horizontal: 8), child: Image.network(images[i], fit: BoxFit.cover), ), )) .toList(), ); }, ) ``` -------------------------------- ### Carousel Slider Builder Usage Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/README.md Implement a carousel slider using a builder function for on-demand item creation, which is memory efficient for large lists. This is suitable for dynamic content. ```dart CarouselSlider.builder( itemCount: 15, itemBuilder: (BuildContext context, int itemIndex, int pageViewIndex) => Container( child: Text(itemIndex.toString()), ), ) ``` -------------------------------- ### Center Page Zoom Enlarge Strategy Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Uses the zoom strategy for an edge-anchored zoom effect on the center page. Configure `enlargeFactor` for the degree of enlargement. ```dart CarouselSlider( options: CarouselOptions( aspectRatio: 2.0, enlargeCenterPage: true, enlargeStrategy: CenterPageEnlargeStrategy.zoom, enlargeFactor: 0.4, // 0.0 = no enlargement, 1.0 = max autoPlay: true, ), items: myWidgets, ) ``` -------------------------------- ### Derive New CarouselOptions with copyWith Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Use `copyWith` to create a new `CarouselOptions` object based on an existing one, overriding specific fields. This is useful for creating variations of a base configuration. ```dart final baseOptions = CarouselOptions( aspectRatio: 16 / 9, autoPlay: true, enlargeCenterPage: true, ); // Reuse base options but switch to vertical scroll for one carousel final verticalOptions = baseOptions.copyWith( scrollDirection: Axis.vertical, autoPlayInterval: Duration(seconds: 5), ); CarouselSlider(items: myItems, options: verticalOptions) ``` -------------------------------- ### CarouselSliderController.jumpToPage Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Jumps instantly to the specified logical page index without any animation. This is ideal for resetting the carousel or navigating directly to a specific item. ```APIDOC ## CarouselSliderController.jumpToPage ### Description Jumps instantly to the specified logical page index without animation. ### Method ```dart _controller.jumpToPage(2); // jump to third item immediately ``` ``` -------------------------------- ### Handling Carousel Page Change Reasons Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Uses the `onPageChanged` callback to detect the reason for a page transition (timed, manual, or controller). This allows for specific actions based on how the page changed. ```dart CarouselSlider( options: CarouselOptions( autoPlay: true, onPageChanged: (index, reason) { switch (reason) { case CarouselPageChangedReason.timed: print('Auto-advanced to $index'); break; case CarouselPageChangedReason.manual: print('User swiped to $index'); break; case CarouselPageChangedReason.controller: print('Programmatically moved to $index'); break; } }, ), items: myItems, ) ``` -------------------------------- ### CarouselSliderController.previousPage Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Animates to the previous page with configurable duration and curve. This is useful for implementing 'previous' navigation buttons. ```APIDOC ## CarouselSliderController.previousPage ### Description Animates to the previous page with configurable duration and curve. ### Method ```dart _controller.previousPage( duration: Duration(milliseconds: 300), curve: Curves.linear, ); ``` ``` -------------------------------- ### CarouselSliderController.nextPage Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Animates to the next page with configurable duration and curve. This method allows for smooth transitions between carousel items. ```APIDOC ## CarouselSliderController.nextPage ### Description Animates to the next page with configurable duration and curve. ### Method ```dart _controller.nextPage( duration: Duration(milliseconds: 300), curve: Curves.linear, ); ``` ``` -------------------------------- ### Add Carousel Slider Dependency Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Add the carousel_slider dependency to your pubspec.yaml file to include it in your Flutter project. ```yaml dependencies: carousel_slider: ^5.1.2 ``` -------------------------------- ### CarouselSliderController.animateToPage Specific Page Animation Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Animates to a specified page index. When infinite scroll is enabled, it respects `animateToClosest` to choose the shortest path. ```dart await _controller.animateToPage( 4, duration: Duration(milliseconds: 500), curve: Curves.easeInOut, ); ``` -------------------------------- ### CarouselSliderController.previousPage Animation Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Animates to the previous page with specified duration and curve. Ideal for implementing previous navigation buttons. ```dart _controller.previousPage( duration: Duration(milliseconds: 300), curve: Curves.linear, ); ``` -------------------------------- ### CarouselSliderController.nextPage Animation Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Animates to the next page with specified duration and curve. Useful for custom navigation controls. ```dart _controller.nextPage( duration: Duration(milliseconds: 300), curve: Curves.linear, ); ``` -------------------------------- ### Register Service Worker for Flutter Web Source: https://github.com/serenader2014/flutter_carousel_slider/blob/master/example/web/index.html Register a service worker for your Flutter web application. This code should be placed in your main HTML file. ```javascript if ('serviceWorker' in navigator) { window.addEventListener('flutter-first-frame', function () { navigator.serviceWorker.register('flutter\_service\_worker.js'); }); } ``` -------------------------------- ### Vertical Carousel Configuration Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Configures the carousel to scroll vertically by setting the `scrollDirection` option to `Axis.vertical`. Includes auto-play settings. ```dart CarouselSlider( options: CarouselOptions( aspectRatio: 2.0, enlargeCenterPage: true, scrollDirection: Axis.vertical, autoPlay: true, autoPlayInterval: Duration(seconds: 2), ), items: [ Colors.red, Colors.green, Colors.blue, Colors.orange, Colors.purple, ].map((color) => Container(color: color)).toList(), ) ``` -------------------------------- ### Preserving Scroll Position with PageStorageKey Source: https://context7.com/serenader2014/flutter_carousel_slider/llms.txt Passes a `PageStorageKey` to `pageViewKey` within `CarouselOptions` to maintain the scroll position when the carousel is nested within scrollable widgets like `ListView`. This prevents the carousel from resetting its position on rebuilds. ```dart ListView.builder( itemBuilder: (ctx, index) { if (index == 2) { return CarouselSlider( options: CarouselOptions( aspectRatio: 2.0, pageViewKey: PageStorageKey('hero_carousel'), ), items: bannerWidgets, ); } return SizedBox(height: 150, child: Placeholder()); }, ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.