Skip to content

Add leadingIndex to CarouselController and onItemChanged to CarouselView#180667

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
Mairramer:feature/add-leadingIndex-and-onItemChanged-to-carousel
Jan 20, 2026
Merged

Add leadingIndex to CarouselController and onItemChanged to CarouselView#180667
auto-submit[bot] merged 5 commits into
flutter:masterfrom
Mairramer:feature/add-leadingIndex-and-onItemChanged-to-carousel

Conversation

@Mairramer

Copy link
Copy Markdown
Contributor

Adds a leadingIndex property to CarouselController and an onItemChanged callback to CarouselView.
Closes #169207

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Jan 7, 2026
@Mairramer Mairramer changed the title Add onIndexChanged callback to CarouselView for leading item updates Add leadingIndex to CarouselController and onItemChanged to CarouselView Jan 7, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an onIndexChanged callback to CarouselView and a leadingItem property to CarouselController, enabling developers to track and query the leading item in the carousel. The implementation correctly uses a NotificationListener to detect scroll changes and trigger the callback. The logic for calculating the leading item index, considering different configurations like flexWeights and consumeMaxWeight, has been added to _CarouselPosition. Additionally, comprehensive tests are included to validate the new functionality under various conditions, such as animations and user gestures. The changes are well-structured and thoroughly tested.

@Piinks Piinks self-requested a review January 7, 2026 23:35
@Piinks

Piinks commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

Self-ping to my inbox for review. Thank you! 🙏

@QuncCccccc QuncCccccc self-requested a review January 13, 2026 20:12
Comment thread packages/flutter/lib/src/material/carousel.dart Outdated
Comment thread packages/flutter/lib/src/material/carousel.dart Outdated
Comment thread packages/flutter/test/material/carousel_test.dart

@QuncCccccc QuncCccccc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some doc comments:)

Comment thread packages/flutter/lib/src/material/carousel.dart Outdated
Comment thread packages/flutter/lib/src/material/carousel.dart Outdated
Comment thread packages/flutter/lib/src/material/carousel.dart Outdated
@Mairramer Mairramer requested a review from Piinks January 14, 2026 22:20

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@QuncCccccc QuncCccccc added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 20, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jan 20, 2026
Merged via the queue into flutter:master with commit c6fad7a Jan 20, 2026
71 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 23, 2026
flutter-zl pushed a commit to flutter-zl/flutter that referenced this pull request Feb 10, 2026
…iew (flutter#180667)

Adds a `leadingIndex` property to CarouselController and an
`onItemChanged` callback to CarouselView.
Closes flutter#169207

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal to add currentIndex to CarouselController and onItemChanged to CarouselView

3 participants