### Install flutter_carousel_widget Source: https://pub.dev/packages/flutter_carousel_widget Add the flutter_carousel_widget package to your pubspec.yaml file and run 'flutter pub get'. ```yaml dependencies: flutter_carousel_widget: ^latest_version ``` -------------------------------- ### Flutter App Entry Point Source: https://pub.dev/packages/flutter_carousel_widget/example This is the main entry point for a Flutter application using the carousel widget. It sets up the MaterialApp with navigation routes for various carousel examples. ```dart import 'package:flutter/material.dart'; import 'app_themes.dart'; import 'views/custom_indicator.dart'; import 'views/enlarge.dart'; import 'views/expandable.dart'; import 'views/fullscreen.dart'; import 'views/home.dart'; import 'views/indicator_halo.dart'; import 'views/manual.dart'; import 'views/multiple_items.dart'; import 'views/page_change_reason.dart'; import 'views/standard.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); runApp(const FlutterCarouselDemo()); } class FlutterCarouselDemo extends StatelessWidget { const FlutterCarouselDemo({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, initialRoute: '/', routes: { '/': (ctx) => const CarouselDemoHome(), '/standard': (ctx) => const StandardCarouselDemo(), '/enlarge': (ctx) => const EnlargeStrategyCarouselDemo(), '/manual': (ctx) => const ManuallyControlledCarouselDemo(), '/fullscreen': (ctx) => const FullscreenCarouselDemo(), '/custom_indicator': (ctx) => const CustomIndicatorCarouselDemo(), '/indicator_halo': (ctx) => const HaloIndicatorCarouselDemo(), '/multiple_items': (ctx) => const MultipleItemsCarouselDemo(), '/expandable': (ctx) => const ExpandableCarouselDemo(), '/page_changed_reason': (ctx) => const PageChangedReasonCarouselDemo(), }, theme: AppThemes.lightTheme, darkTheme: AppThemes.darkTheme, themeMode: ThemeMode.system, ); } } ``` -------------------------------- ### Implement Custom Slide Percentage Indicator Source: https://pub.dev/packages/flutter_carousel_widget Create a custom slide indicator that displays the current page percentage. This example implements the SlideIndicator contract to show a percentage value based on the current page, page delta, and total item count. ```dart class SlidePercentageIndicator implements SlideIndicator { SlidePercentageIndicator({ this.decimalPlaces = 0, this.style, }); /// The number of decimal places to show in the output final int decimalPlaces; /// The text style to be used by the percentage text final TextStyle? style; @override Widget build(int currentPage, double pageDelta, int itemCount) { if (itemCount < 2) return const SizedBox.shrink(); final step = 100 / (itemCount - 1); final percentage = step * (pageDelta + currentPage); return Center( child: Text( '${percentage.toStringAsFixed(decimalPlaces)}%', style: style ?? const TextStyle( fontSize: 24, fontWeight: FontWeight.w600, ), ), ); } } ``` -------------------------------- ### Add flutter_carousel_widget Dependency to pubspec.yaml Source: https://pub.dev/packages/flutter_carousel_widget/install This is an example of how the flutter_carousel_widget dependency will appear in your pubspec.yaml file after running the `flutter pub add` command. ```yaml dependencies: flutter_carousel_widget: ^3.1.0 ``` -------------------------------- ### Import flutter_carousel_widget in Dart Source: https://pub.dev/packages/flutter_carousel_widget/install Import the package into your Dart code to start using its widgets and functionalities. ```dart import 'package:flutter_carousel_widget/flutter_carousel_widget.dart'; ``` -------------------------------- ### Implement ExpandableCarousel Source: https://pub.dev/packages/flutter_carousel_widget Creates a carousel that automatically adjusts its height to fit the current child widget. ```dart ExpandableCarousel( options: ExpandableCarouselOptions( autoPlay: true, autoPlayInterval: const Duration(seconds: 2), ), 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 Carousel Items on Demand Source: https://pub.dev/packages/flutter_carousel_widget Uses the builder pattern to lazily load items, improving memory efficiency for large lists. ```dart FlutterCarousel.builder( itemCount: 15, itemBuilder: (BuildContext context, int itemIndex, int pageViewIndex) => Container( child: Text(itemIndex.toString()), ), ) ``` ```dart ExpandableCarousel.builder( itemCount: 15, itemBuilder: (BuildContext context, int itemIndex, int pageViewIndex) => Container( child: Text(itemIndex.toString()), ), ) ``` -------------------------------- ### Add flutter_carousel_widget Dependency Source: https://pub.dev/packages/flutter_carousel_widget/install Use this command to add the package as a dependency to your Flutter project. This command automatically updates your pubspec.yaml file. ```bash $ flutter pub add flutter_carousel_widget ``` -------------------------------- ### Using FlutterCarousel Widget Source: https://pub.dev/packages/flutter_carousel_widget Implement a Flutter carousel with infinite scrolling, auto-scrolling, and custom indicators. Ensure to provide a list of widgets for the 'items' property. ```dart FlutterCarousel( options: FlutterCarouselOptions( height: 400.0, showIndicator: true, slideIndicator: CircularSlideIndicator(), ), 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(), ) ``` -------------------------------- ### Customize FlutterCarousel Options Source: https://pub.dev/packages/flutter_carousel_widget Configures various properties of the FlutterCarousel widget, including animation, scrolling behavior, and indicator settings. ```dart FlutterCarousel( items: items, options: FlutterCarouselOptions( height: 400.0, // Sets the height of the carousel widget. aspectRatio: 16 / 9, // Defines the aspect ratio of the carousel widget. viewportFraction: 1.0, // Fraction of the viewport that each page should occupy. initialPage: 0, // The initial page to display when the carousel is first shown. enableInfiniteScroll: true, // Enables infinite looping of the carousel items. reverse: false, // Reverses the order of the carousel items. autoPlay: false, // Enables automatic scrolling through the carousel items. autoPlayInterval: const Duration(seconds: 2), // Duration between automatic scrolls when autoPlay is enabled. autoPlayAnimationDuration: const Duration(milliseconds: 800), // Duration of the animation when automatically scrolling between items. autoPlayCurve: Curves.fastOutSlowIn, // Curve for the auto-play animation to control the animation's speed. enlargeCenterPage: false, // Enlarges the center page of the carousel to make it more prominent. controller: CarouselController(), // Controls the carousel programmatically. onPageChanged: callbackFunction, // Callback function that is triggered when the page is changed. pageSnapping: true, // Enables snapping of the carousel pages to ensure they stop at each item. scrollDirection: Axis.horizontal, // Direction of the carousel scroll (horizontal or vertical). pauseAutoPlayOnTouch: true, // Pauses auto-play when the user touches the carousel. pauseAutoPlayOnManualNavigate: true, // Pauses auto-play when the user manually navigates through the carousel. pauseAutoPlayInFiniteScroll: false, // Pauses auto-play in infinite scroll mode. enlargeStrategy: CenterPageEnlargeStrategy.scale, // Strategy to enlarge the center page, such as scaling or zooming. disableCenter: false, // Disables centering of the carousel items. showIndicator: true, // Shows an indicator to display the current slide position. floatingIndicator: true, // Shows a floating indicator above the carousel. slideIndicator: CircularSlideIndicator(), // Sets a custom indicator widget for the carousel slides. ) ) ``` -------------------------------- ### Customize Circular Slide Indicator Options Source: https://pub.dev/packages/flutter_carousel_widget Configure the appearance and behavior of the CircularSlideIndicator using SlideIndicatorOptions. This includes setting colors, sizes, spacing, and halo effects. ```dart FlutterCarousel( ... options: FlutterCarouselOptions( ... slideIndicator: CircularSlideIndicator( slideIndicatorOptions: SlideIndicatorOptions( /// The alignment of the indicator. alignment: Alignment.bottomCenter, /// The color of the currently active item indicator. currentIndicatorColor: Colors.white, /// The background color of all inactive item indicators. indicatorBackgroundColor: Colors.white.withOpacity(0.5), /// The border color of all item indicators. indicatorBorderColor: Colors.white, /// The border width of all item indicators. indicatorBorderWidth: 1, /// The radius of all item indicators. indicatorRadius: 6, /// The spacing between each item indicator. itemSpacing: 20, /// The padding of the indicator. padding: const EdgeInsets.all(8.0), /// The decoration of the indicator halo. haloDecoration: BoxDecoration( borderRadius: const BorderRadius.all(Radius.circular(15.0)), color: Colors.black.withOpacity(0.5)), /// The padding of the indicator halo. haloPadding: const EdgeInsets.all(8.0), /// Whether to enable the indicator halo. enableHalo: true, /// Whether to enable the animation. Only used in [CircularStaticIndicator] and [SequentialFillIndicator]. enableAnimation: true, ), ), ), ); ``` -------------------------------- ### Control Carousel Programmatically Source: https://pub.dev/packages/flutter_carousel_widget Uses a FlutterCarouselController to trigger navigation actions like moving to the next page. ```dart class CarouselDemo extends StatelessWidget { FlutterCarouselController buttonCarouselController = FlutterCarouselController(); @override Widget build(BuildContext context) => Column( children: [ FlutterCarousel( items: child, options: FlutterCarouselOptions( autoPlay: false, controller: buttonCarouselController, enlargeCenterPage: true, viewportFraction: 0.9, aspectRatio: 2.0, initialPage: 2, ), ), RaisedButton( onPressed: () => buttonCarouselController.nextPage( duration: Duration(milliseconds: 300), curve: Curves.linear), child: Text('→'), ) ] ); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.