-
Notifications
You must be signed in to change notification settings - Fork 1
feat: added customizable page indicator widget #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Hirdaya-Shrestha
wants to merge
10
commits into
GalaxyPhoenix716:main
from
Hirdaya-Shrestha:feature/page-indicator-widget
Closed
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9a228cb
feat: added customizable page indicator widget
Hirdaya-Shrestha 1bf15b9
fix: page indicator boundary wrap, touch targets, ignore pointer
Hirdaya-Shrestha a1a04b0
Potential fix for pull request finding
Hirdaya-Shrestha 1a014e9
style: dart format
Hirdaya-Shrestha c851388
Potential fix for pull request finding
Hirdaya-Shrestha 681fc56
style: dart format
Hirdaya-Shrestha 5191af2
fix: simplify wrap animation and fix active pill position
Hirdaya-Shrestha 2d6612a
Potential fix for pull request finding
Hirdaya-Shrestha 940f724
Potential fix for pull request finding
Hirdaya-Shrestha a341934
Merge branch 'GalaxyPhoenix716:main' into feature/page-indicator-widget
Hirdaya-Shrestha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'coverflow_carousel_controller.dart'; | ||
|
|
||
| const double _tapTargetSize = 40.0; | ||
|
|
||
| /// Shows the current page as a sliding pill over dots. | ||
| /// | ||
| /// Listens to [controller]'s [ValueNotifier] and animates the active | ||
| /// indicator between pages as the carousel scrolls. | ||
| class CoverflowPageIndicator extends StatelessWidget { | ||
| const CoverflowPageIndicator({ | ||
| super.key, | ||
| required this.controller, | ||
| required this.itemCount, | ||
| this.activeColor = Colors.white, | ||
| this.inactiveColor = Colors.white38, | ||
| this.dotSize = 8.0, | ||
| this.dotSpacing = 12.0, | ||
| this.onTap, | ||
| }); | ||
|
Hirdaya-Shrestha marked this conversation as resolved.
Outdated
Hirdaya-Shrestha marked this conversation as resolved.
Outdated
|
||
|
|
||
| final CoverflowCarouselController controller; | ||
| final int itemCount; | ||
| final Color activeColor; | ||
| final Color inactiveColor; | ||
| final double dotSize; | ||
| final double dotSpacing; | ||
| final void Function(int index)? onTap; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| final step = dotSize + dotSpacing; | ||
|
|
||
| return ValueListenableBuilder<double>( | ||
| valueListenable: controller.pageListenable, | ||
| builder: (context, page, _) { | ||
| if (itemCount <= 0) return const SizedBox.shrink(); | ||
|
|
||
| final count = itemCount; | ||
| final clamped = page.clamp(0.0, count.toDouble() - 1e-9).toDouble(); | ||
| final floor = clamped.floor(); | ||
| final t = clamped - floor; | ||
| final indexB = (floor + 1) % count; | ||
| final isWrapping = count > 1 && indexB == 0 && floor == count - 1; | ||
|
|
||
| return SizedBox( | ||
| width: count * dotSize + (count - 1) * dotSpacing, | ||
| height: dotSize + 8, | ||
| child: Stack( | ||
| clipBehavior: Clip.none, | ||
| children: [ | ||
| for (final i in List.generate(count, (i) => i)) | ||
| Positioned( | ||
| left: i * step - (_tapTargetSize - dotSize) / 2, | ||
| top: 4 - (_tapTargetSize - dotSize) / 2, | ||
| width: _tapTargetSize, | ||
| height: _tapTargetSize, | ||
| child: GestureDetector( | ||
|
Hirdaya-Shrestha marked this conversation as resolved.
|
||
| onTap: onTap != null ? () => onTap!(i) : null, | ||
| behavior: HitTestBehavior.opaque, | ||
| child: Center( | ||
| child: Container( | ||
| width: dotSize, | ||
| height: dotSize, | ||
| decoration: BoxDecoration( | ||
| shape: BoxShape.circle, | ||
| color: inactiveColor, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| if (isWrapping && t > 0.5) ...[ | ||
| _buildActivePill(left: 0, width: dotSize * ((t - 0.5) / 0.5)), | ||
| _buildActivePill( | ||
| left: floor * step, | ||
| width: dotSize * (1.0 - (t - 0.5) / 0.5), | ||
| ), | ||
| ] else | ||
| _buildActivePill( | ||
| left: floor * step + (t < 0.5 ? 0 : ((t - 0.5) / 0.5) * step), | ||
| width: | ||
| dotSize + | ||
| (t < 0.5 | ||
| ? (t / 0.5) * step | ||
| : (1.0 - (t - 0.5) / 0.5) * step), | ||
| ), | ||
| ], | ||
| ), | ||
| ); | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| Widget _buildActivePill({required double left, required double width}) { | ||
| return Positioned( | ||
| left: left, | ||
| top: 4, | ||
| width: width, | ||
| height: dotSize, | ||
|
Hirdaya-Shrestha marked this conversation as resolved.
|
||
| child: IgnorePointer( | ||
|
Hirdaya-Shrestha marked this conversation as resolved.
|
||
| child: Container( | ||
| decoration: BoxDecoration( | ||
| color: activeColor, | ||
| borderRadius: BorderRadius.circular(dotSize / 2), | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.