FlutterCarousel class
A carousel of items that share one size: a fixed height, or an aspectRatio of the available width.
For items that size themselves, use ExpandableCarousel.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- FlutterCarousel
Constructors
-
FlutterCarousel({Key? key, required List<
Widget> items, double? height, double aspectRatio = 1.0, FlutterCarouselController? controller, int initialPage = 0, double viewportFraction = 0.8, bool infinite = false, bool reverse = false, Axis scrollDirection = Axis.horizontal, CarouselAutoPlay? autoPlay, CarouselEffect effect = CarouselEffect.none, CarouselIndicator? indicator = const CarouselIndicator(), CarouselPageChanged? onPageChanged, ValueChanged<double> ? onScrolled, AlignmentGeometry? itemAlignment = Alignment.center, bool keepAlive = false, String? semanticLabel, String semanticSlideLabel(int index, int count)?, FocusNode? focusNode, bool autofocus = false, ScrollPhysics? physics, bool pageSnapping = true, bool padEnds = true, CarouselEdgeAlignment edgeAlignment = CarouselEdgeAlignment.center, Clip clipBehavior = Clip.antiAlias, ScrollBehavior? scrollBehavior, DragStartBehavior dragStartBehavior = DragStartBehavior.start, bool allowImplicitScrolling = false, String? restorationId, bool keepPage = true, PageStorageKey<Object?> ? pageViewKey}) -
Creates a carousel of
items.const -
FlutterCarousel.builder({Key? key, required int itemCount, required CarouselItemBuilder itemBuilder, double? height, double aspectRatio = 1.0, FlutterCarouselController? controller, int initialPage = 0, double viewportFraction = 0.8, bool infinite = false, bool reverse = false, Axis scrollDirection = Axis.horizontal, CarouselAutoPlay? autoPlay, CarouselEffect effect = CarouselEffect.none, CarouselIndicator? indicator = const CarouselIndicator(), CarouselPageChanged? onPageChanged, ValueChanged<
double> ? onScrolled, AlignmentGeometry? itemAlignment = Alignment.center, bool keepAlive = false, String? semanticLabel, String semanticSlideLabel(int index, int count)?, FocusNode? focusNode, bool autofocus = false, ScrollPhysics? physics, bool pageSnapping = true, bool padEnds = true, CarouselEdgeAlignment edgeAlignment = CarouselEdgeAlignment.center, Clip clipBehavior = Clip.antiAlias, ScrollBehavior? scrollBehavior, DragStartBehavior dragStartBehavior = DragStartBehavior.start, bool allowImplicitScrolling = false, String? restorationId, bool keepPage = true, PageStorageKey<Object?> ? pageViewKey}) -
Creates a carousel that builds
itemCountitems on demand.const
Properties
- allowImplicitScrolling → bool
-
Whether the pages next to the current one are built for accessibility.
final
- aspectRatio → double
-
The carousel's width over its height, used when height is
null.final - autofocus → bool
-
Whether the carousel takes focus when first built.
final
- autoPlay → CarouselAutoPlay?
-
Moves the carousel on by itself;
nullturns autoplay off.final - clipBehavior → Clip
-
How the pages clip.
final
- controller → FlutterCarouselController?
-
Drives the carousel and reports its state.
final
- dragStartBehavior → DragStartBehavior
-
When a drag starts.
final
- edgeAlignment → CarouselEdgeAlignment
-
Where the first and last items settle; ignored when infinite.
CarouselEdgeAlignment.flush keeps middle items centred, which
padEnds: falsedoes not. It needs a viewportFraction above 1/3.final - effect → CarouselEffect
-
How items transform as they move.
final
- focusNode → FocusNode?
-
The carousel's focus node, for keyboard navigation.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → double?
-
The carousel's height. Wins over aspectRatio.
final
- indicator → CarouselIndicator?
-
The page indicator;
nullhides it. It shows only for two or more items.final - infinite → bool
-
Whether the carousel loops past its last item to its first.
final
- initialPage → int
-
The item shown first.
final
- itemAlignment → AlignmentGeometry?
-
Aligns each item in its page;
nullpasses the page's constraints through unchanged, which lets an image fill its page.final - itemBuilder → CarouselItemBuilder?
-
Builds the items on demand.
final
- itemCount → int?
-
How many items itemBuilder builds.
final
-
items
→ List<
Widget> ? -
The items, when built from a list. Items with keys keep their state when
the list changes around them.
final
- keepAlive → bool
-
Whether pages keep their state while scrolled out of view.
final
- keepPage → bool
-
Whether the page is saved in
PageStorageand restored.final - key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
Whether the arrow, Home and End keys move the focused carousel.
final
- onPageChanged → CarouselPageChanged?
-
Called when the current item changes, with what moved it. Like
PageView.onPageChanged, it fires as the rounded position crosses to another item, so a long move reports the items it passes.final -
onScrolled
→ ValueChanged<
double> ? -
Called on every scroll frame with the fractional item position, in
[0, itemCount).final - padEnds → bool
-
Whether the first and last pages can sit in the middle of the viewport.
final
- pageSnapping → bool
-
Whether a drag settles on a page.
final
-
pageViewKey
→ PageStorageKey<
Object?> ? -
The key of the underlying
PageView, forPageStorage.final - physics → ScrollPhysics?
-
How the pages respond to drags.
nulluses CarouselSnapPhysics over the platform's physics.final - restorationId → String?
-
Restores the scroll offset.
final
- reverse → bool
-
Whether the items run in reverse. Autoplay then moves backwards too.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scrollBehavior → ScrollBehavior?
-
The scroll behavior.
nulllets every pointer kind drag, trackpads included, and hides scrollbars and overscroll indicators.final - scrollDirection → Axis
-
The scroll axis.
final
- semanticLabel → String?
-
The carousel's label for screen readers.
nulluses "Carousel".final - semanticSlideLabel → String Function(int index, int count)?
-
Labels an item for screen readers.
nulluses "Slide 2 of 5".final - viewportFraction → double
-
The share of the viewport each page takes; below 1 the neighbours peek in.
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited