✨ Shuffle mode swiper
This commit is contained in:
@ -182,7 +182,10 @@ class _PostItemState extends State<PostItem> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final hasAttachment = item.body['attachments']?.isNotEmpty ?? false;
|
||||
final List<int> attachments = item.body['attachments'] is List
|
||||
? item.body['attachments']?.cast<int>()
|
||||
: List.empty();
|
||||
final hasAttachment = attachments.isNotEmpty;
|
||||
|
||||
if (widget.isCompact) {
|
||||
return Column(
|
||||
@ -199,7 +202,7 @@ class _PostItemState extends State<PostItem> {
|
||||
bottom: hasAttachment ? 4 : 0,
|
||||
),
|
||||
buildFooter().paddingOnly(left: 16),
|
||||
if (item.body['attachments']?.isNotEmpty ?? false)
|
||||
if (attachments.isNotEmpty)
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
@ -209,7 +212,7 @@ class _PostItemState extends State<PostItem> {
|
||||
).paddingOnly(right: 6),
|
||||
Text(
|
||||
'postAttachmentTip'.trParams(
|
||||
{'count': item.body['attachments']!.length.toString()},
|
||||
{'count': attachments.length.toString()},
|
||||
),
|
||||
style: TextStyle(color: _unFocusColor),
|
||||
)
|
||||
@ -293,8 +296,7 @@ class _PostItemState extends State<PostItem> {
|
||||
),
|
||||
child: AttachmentList(
|
||||
parentId: widget.item.id.toString(),
|
||||
attachmentsId:
|
||||
item.body['attachments']?.cast<int>() ?? List.empty(),
|
||||
attachmentsId: attachments,
|
||||
divided: true,
|
||||
),
|
||||
),
|
||||
|
62
lib/widgets/posts/post_shuffle_swiper.dart
Normal file
62
lib/widgets/posts/post_shuffle_swiper.dart
Normal file
@ -0,0 +1,62 @@
|
||||
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';
|
||||
|
||||
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];
|
||||
return PostSingleDisplay(
|
||||
key: Key('p${element.id}'),
|
||||
item: element,
|
||||
);
|
||||
},
|
||||
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();
|
||||
}
|
||||
}
|
24
lib/widgets/posts/post_single_display.dart
Normal file
24
lib/widgets/posts/post_single_display.dart
Normal file
@ -0,0 +1,24 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:solian/models/post.dart';
|
||||
import 'package:solian/widgets/posts/post_item.dart';
|
||||
|
||||
class PostSingleDisplay extends StatelessWidget {
|
||||
final Post item;
|
||||
|
||||
const PostSingleDisplay({super.key, required this.item});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
child: Card(
|
||||
child: SingleChildScrollView(
|
||||
child: PostItem(
|
||||
item: item,
|
||||
).paddingSymmetric(horizontal: 10, vertical: 16),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user