Skip to content

Commit

Permalink
fix(homepage): Fix reset swipper
Browse files Browse the repository at this point in the history
  • Loading branch information
realth000 committed Aug 25, 2024
1 parent ab28e0b commit 5c74ccc
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions lib/features/homepage/widgets/welcome_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class WelcomeSection extends StatefulWidget {
class _WelcomeSectionState extends State<WelcomeSection> with LoggerMixin {
late final CarouselController _swiperController;
Timer? _swiperTimer;
bool _reverseSwiper = false;

Widget _buildKahrpbaSwiper(
BuildContext context,
Expand All @@ -42,6 +43,7 @@ class _WelcomeSectionState extends State<WelcomeSection> with LoggerMixin {
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: _kahrpbaPicHeight + 20),
child: CarouselView(
reverse: _reverseSwiper,
controller: _swiperController,
itemSnapping: true,
itemExtent: _kahrpbaPicWidth,
Expand Down Expand Up @@ -231,13 +233,31 @@ class _WelcomeSectionState extends State<WelcomeSection> with LoggerMixin {

void setupSwiperTimer(int itemCount) {
_swiperTimer = Timer.periodic(const Duration(seconds: 4), (timer) {
_swiperController.animateTo(
_swiperController.offset >= (itemCount - 2) * _kahrpbaPicWidth
? 0
: _swiperController.offset + _kahrpbaPicWidth,
duration: duration200,
curve: Curves.ease,
);
double? target;
if (_reverseSwiper) {
if (_swiperController.offset <= 100) {
setState(() {
_reverseSwiper = false;
});
} else {
target = _swiperController.offset - _kahrpbaPicWidth;
}
} else {
if (_swiperController.offset >= (itemCount - 3) * _kahrpbaPicWidth) {
setState(() {
_reverseSwiper = true;
});
} else {
target = _swiperController.offset + _kahrpbaPicWidth;
}
}
if (target != null) {
_swiperController.animateTo(
target,
duration: duration200,
curve: Curves.ease,
);
}
});
}

Expand Down

0 comments on commit 5c74ccc

Please sign in to comment.