2024-05-25 09:21:27 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
|
|
|
import 'package:solian/models/post.dart';
|
2024-07-25 17:16:32 +00:00
|
|
|
import 'package:solian/providers/auth.dart';
|
2024-05-25 09:21:27 +00:00
|
|
|
import 'package:solian/widgets/posts/post_action.dart';
|
|
|
|
import 'package:solian/widgets/posts/post_item.dart';
|
|
|
|
|
|
|
|
class PostListWidget extends StatelessWidget {
|
|
|
|
final bool isShowEmbed;
|
|
|
|
final bool isClickable;
|
|
|
|
final bool isNestedClickable;
|
|
|
|
final PagingController<int, Post> controller;
|
2024-08-01 21:10:10 +00:00
|
|
|
final Color? backgroundColor;
|
2024-05-25 09:21:27 +00:00
|
|
|
|
|
|
|
const PostListWidget({
|
|
|
|
super.key,
|
|
|
|
required this.controller,
|
|
|
|
this.isShowEmbed = true,
|
|
|
|
this.isClickable = true,
|
|
|
|
this.isNestedClickable = true,
|
2024-08-01 21:10:10 +00:00
|
|
|
this.backgroundColor,
|
2024-05-25 09:21:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-05-29 12:13:53 +00:00
|
|
|
return PagedSliverList<int, Post>.separated(
|
2024-07-11 16:44:57 +00:00
|
|
|
addRepaintBoundaries: true,
|
2024-05-25 09:21:27 +00:00
|
|
|
pagingController: controller,
|
|
|
|
builderDelegate: PagedChildBuilderDelegate<Post>(
|
|
|
|
itemBuilder: (context, item, index) {
|
2024-08-01 20:59:35 +00:00
|
|
|
return PostListEntryWidget(
|
|
|
|
isShowEmbed: isShowEmbed,
|
|
|
|
isNestedClickable: isNestedClickable,
|
|
|
|
isClickable: isClickable,
|
2024-09-16 15:35:44 +00:00
|
|
|
showFeaturedReply: true,
|
2024-08-01 20:59:35 +00:00
|
|
|
item: item,
|
2024-08-01 21:10:10 +00:00
|
|
|
backgroundColor: backgroundColor,
|
2024-08-01 20:59:35 +00:00
|
|
|
onUpdate: () {
|
|
|
|
controller.refresh();
|
|
|
|
},
|
2024-05-25 09:21:27 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
separatorBuilder: (_, __) => const Divider(thickness: 0.3, height: 0.3),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-07-07 03:46:48 +00:00
|
|
|
|
|
|
|
class PostListEntryWidget extends StatelessWidget {
|
2024-07-31 17:21:27 +00:00
|
|
|
final int renderOrder;
|
2024-07-07 03:46:48 +00:00
|
|
|
final bool isShowEmbed;
|
|
|
|
final bool isNestedClickable;
|
|
|
|
final bool isClickable;
|
2024-09-16 15:35:44 +00:00
|
|
|
final bool showFeaturedReply;
|
2024-07-07 03:46:48 +00:00
|
|
|
final Post item;
|
|
|
|
final Function onUpdate;
|
2024-08-01 21:10:10 +00:00
|
|
|
final Color? backgroundColor;
|
2024-07-07 03:46:48 +00:00
|
|
|
|
|
|
|
const PostListEntryWidget({
|
|
|
|
super.key,
|
2024-07-31 17:21:27 +00:00
|
|
|
this.renderOrder = 0,
|
2024-07-07 03:46:48 +00:00
|
|
|
required this.isShowEmbed,
|
|
|
|
required this.isNestedClickable,
|
|
|
|
required this.isClickable,
|
2024-09-16 15:35:44 +00:00
|
|
|
required this.showFeaturedReply,
|
2024-07-07 03:46:48 +00:00
|
|
|
required this.item,
|
|
|
|
required this.onUpdate,
|
2024-08-01 21:10:10 +00:00
|
|
|
this.backgroundColor,
|
2024-07-07 03:46:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return GestureDetector(
|
|
|
|
child: PostItem(
|
2024-07-23 10:09:41 +00:00
|
|
|
key: Key('p${item.id}'),
|
2024-07-07 03:46:48 +00:00
|
|
|
item: item,
|
|
|
|
isShowEmbed: isShowEmbed,
|
|
|
|
isClickable: isNestedClickable,
|
2024-09-16 15:35:44 +00:00
|
|
|
showFeaturedReply: showFeaturedReply,
|
2024-08-01 21:10:10 +00:00
|
|
|
backgroundColor: backgroundColor,
|
2024-07-07 03:46:48 +00:00
|
|
|
).paddingSymmetric(vertical: 8),
|
|
|
|
onLongPress: () {
|
2024-07-25 17:16:32 +00:00
|
|
|
final AuthProvider auth = Get.find();
|
|
|
|
if (auth.isAuthorized.isFalse) return;
|
|
|
|
|
2024-07-07 03:46:48 +00:00
|
|
|
showModalBottomSheet(
|
|
|
|
useRootNavigator: true,
|
|
|
|
context: context,
|
|
|
|
builder: (context) => PostAction(item: item),
|
|
|
|
).then((value) {
|
2024-08-04 10:13:59 +00:00
|
|
|
if (value is Future) {
|
|
|
|
value.then((_) {
|
|
|
|
onUpdate();
|
|
|
|
});
|
|
|
|
} else if (value != null) {
|
|
|
|
onUpdate();
|
|
|
|
}
|
2024-07-07 03:46:48 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|