diff --git a/modules/ensemble/assets/schema/ensemble_schema.json b/modules/ensemble/assets/schema/ensemble_schema.json index 2f2927182..d7c80d4ed 100644 --- a/modules/ensemble/assets/schema/ensemble_schema.json +++ b/modules/ensemble/assets/schema/ensemble_schema.json @@ -3460,6 +3460,14 @@ "indicatorPadding": { "$ref": "#/$defs/Padding-payload", "description": "The padding around the indicator" + }, + "indicatorLeadingWidget": { + "type": "object", + "description": "Widget displayed before the indicator row or column" + }, + "indicatorTrailingWidget": { + "type": "object", + "description": "Widget displayed after the indicator row or column" } } } @@ -8190,4 +8198,4 @@ } } } -} \ No newline at end of file +} diff --git a/modules/ensemble/lib/widget/carousel.dart b/modules/ensemble/lib/widget/carousel.dart index a7d5b623b..adc80c494 100644 --- a/modules/ensemble/lib/widget/carousel.dart +++ b/modules/ensemble/lib/widget/carousel.dart @@ -85,6 +85,10 @@ class Carousel extends StatefulWidget 'indicatorWidget': (widget) => _controller.indicatorWidget = widget, 'selectedIndicatorWidget': (widget) => _controller.selectedIndicatorWidget = widget, + 'indicatorLeadingWidget': (widget) => + _controller.indicatorLeadingWidget = widget, + 'indicatorTrailingWidget': (widget) => + _controller.indicatorTrailingWidget = widget, 'aspectRatio': (value) => _controller.aspectRatio = Utils.optionalDouble(value), 'autoPlayAnimationDuration': (value) => @@ -192,6 +196,8 @@ class MyController extends BoxController { // Custom Widget dynamic indicatorWidget; dynamic selectedIndicatorWidget; + dynamic indicatorLeadingWidget; + dynamic indicatorTrailingWidget; // for single view the current item index is dispatched, // for multi view this dispatch when clicking on a card @@ -213,6 +219,8 @@ class CarouselState extends EWidgetState Widget? customIndicator; Widget? selectedCustomIndicator; + Widget? leadingIndicatorWidget; + Widget? trailingIndicatorWidget; int indicatorIndex = 0; @@ -371,6 +379,10 @@ class CarouselState extends EWidgetState _buildIndicatorWidget(widget._controller.indicatorWidget, scopeManager); selectedCustomIndicator = _buildIndicatorWidget( widget._controller.selectedIndicatorWidget, scopeManager); + leadingIndicatorWidget = _buildIndicatorWidget( + widget._controller.indicatorLeadingWidget, scopeManager); + trailingIndicatorWidget = _buildIndicatorWidget( + widget._controller.indicatorTrailingWidget, scopeManager); // if we should display one at a time or multiple in the slider bool singleView = isSingleView(); @@ -398,6 +410,29 @@ class CarouselState extends EWidgetState if (widget._controller.indicatorType != null && widget._controller.indicatorType != IndicatorType.none) { List indicators = buildIndicators(items); + final bool isVertical = + widget._controller.direction == Axis.vertical.name; + final Widget indicatorRow = isVertical + ? Column( + mainAxisSize: MainAxisSize.min, + children: indicators, + ) + : Row( + mainAxisSize: MainAxisSize.min, + children: indicators, + ); + + final List indicatorChildren = []; + + if (leadingIndicatorWidget != null) { + indicatorChildren.add(leadingIndicatorWidget!); + } + + indicatorChildren.add(indicatorRow); + + if (trailingIndicatorWidget != null) { + indicatorChildren.add(trailingIndicatorWidget!); + } List children = [ carousel, @@ -407,15 +442,19 @@ class CarouselState extends EWidgetState widget._controller.indicatorPosition ?? Alignment.bottomCenter, child: Padding( padding: widget._controller.indicatorPadding ?? EdgeInsets.zero, - child: widget._controller.direction == Axis.vertical.name - ? Column( - mainAxisSize: MainAxisSize.min, - children: indicators, - ) - : Row( - mainAxisSize: MainAxisSize.min, - children: indicators, - ), + child: indicatorChildren.length == 1 + ? indicatorChildren.first + : widget._controller.direction == Axis.vertical.name + ? Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: indicatorChildren, + ) + : Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: indicatorChildren, + ), ), ), )