Skip to content
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

YaruCarousel: allow more actions #117

Merged
merged 2 commits into from
May 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 39 additions & 15 deletions lib/src/yaru_carousel.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'package:flutter/material.dart';

const _kAnimationDuration = Duration(milliseconds: 500);
const _kAnimationCurve = Curves.easeInOutCubic;

class YaruCarousel extends StatefulWidget {
const YaruCarousel({
Key? key,
Expand Down Expand Up @@ -53,10 +56,18 @@ class _YaruCarouselState extends State<YaruCarousel> {
controller: _pageController,
onPageChanged: (index) => setState(() => _index = index),
itemBuilder: (context, index) => AnimatedContainer(
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOutCubic,
duration: _kAnimationDuration,
curve: _kAnimationCurve,
margin: EdgeInsets.all(index == _index ? 10 : 20),
child: widget.children[index],
child: _index == index
? widget.children[index]
: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => _animateToPage(index),
child: IgnorePointer(
child: widget.children[index],
),
),
)),
),
widget.children.length < 30
Expand All @@ -72,18 +83,23 @@ class _YaruCarouselState extends State<YaruCarousel> {
children: List<Widget>.generate(
widget.children.length,
(index) => Expanded(
child: Container(
margin: const EdgeInsets.all(5),
width: 12,
height: 12,
decoration: BoxDecoration(
color: _index == index
? Theme.of(context).colorScheme.primary
: Theme.of(context)
.colorScheme
.primary
.withOpacity(0.3),
shape: BoxShape.circle),
child: GestureDetector(
onTap: _index == index
? null
: () => _animateToPage(index),
child: Container(
margin: const EdgeInsets.all(5),
width: 12,
height: 12,
decoration: BoxDecoration(
color: _index == index
? Theme.of(context).colorScheme.primary
: Theme.of(context)
.colorScheme
.primary
.withOpacity(0.3),
shape: BoxShape.circle),
),
),
),
),
Expand All @@ -107,4 +123,12 @@ class _YaruCarouselState extends State<YaruCarousel> {
],
);
}

void _animateToPage(int pageIndex) {
_pageController.animateToPage(
pageIndex,
duration: _kAnimationDuration,
curve: _kAnimationCurve,
);
}
}