2024-07-25 08:08:46 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_card_swiper/flutter_card_swiper.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:solian/controllers/post_list_controller.dart';
|
|
|
|
import 'package:solian/widgets/posts/post_single_display.dart';
|
2024-07-26 06:21:00 +00:00
|
|
|
import 'package:solian/widgets/sized_container.dart';
|
2024-07-25 08:08:46 +00:00
|
|
|
|
|
|
|
class PostShuffleSwiper extends StatefulWidget {
|
|
|
|
final PostListController controller;
|
|
|
|
|
|
|
|
const PostShuffleSwiper({super.key, required this.controller});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<PostShuffleSwiper> createState() => _PostShuffleSwiperState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PostShuffleSwiperState extends State<PostShuffleSwiper> {
|
|
|
|
final CardSwiperController _swiperController = CardSwiperController();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Obx(
|
|
|
|
() => CardSwiper(
|
|
|
|
initialIndex: 0,
|
|
|
|
isLoop: false,
|
|
|
|
controller: _swiperController,
|
|
|
|
cardsCount: widget.controller.postTotal.value,
|
|
|
|
numberOfCardsDisplayed: 2,
|
|
|
|
allowedSwipeDirection: const AllowedSwipeDirection.symmetric(
|
|
|
|
horizontal: true,
|
|
|
|
),
|
|
|
|
cardBuilder: (context, index, percentThresholdX, percentThresholdY) {
|
|
|
|
if (widget.controller.postList.length <= index) {
|
|
|
|
return Card(
|
|
|
|
child: const Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
).paddingAll(24),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
final element = widget.controller.postList[index];
|
2024-07-26 06:21:00 +00:00
|
|
|
return CenteredContainer(
|
|
|
|
child: PostSingleDisplay(
|
|
|
|
key: Key('p${element.id}'),
|
|
|
|
item: element,
|
|
|
|
onUpdate: () {
|
|
|
|
widget.controller.reloadAllOver();
|
|
|
|
},
|
|
|
|
),
|
2024-07-25 08:08:46 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
padding: const EdgeInsets.all(24),
|
|
|
|
onSwipe: (prevIndex, currIndex, dir) {
|
|
|
|
if (prevIndex + 2 >= widget.controller.postList.length) {
|
|
|
|
// Automatically load more
|
|
|
|
widget.controller.loadMore();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
).paddingOnly(bottom: MediaQuery.of(context).padding.bottom),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_swiperController.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
}
|