Solian/lib/widgets/posts/post_list.dart

93 lines
2.5 KiB
Dart
Raw Normal View History

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';
import 'package:solian/router.dart';
2024-07-12 08:19:54 +00:00
import 'package:solian/widgets/sized_container.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;
const PostListWidget({
super.key,
required this.controller,
this.isShowEmbed = true,
this.isClickable = true,
this.isNestedClickable = true,
});
@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-07-11 16:44:57 +00:00
return CenteredContainer(
child: PostListEntryWidget(
isShowEmbed: isShowEmbed,
isNestedClickable: isNestedClickable,
isClickable: isClickable,
item: item,
onUpdate: () {
controller.refresh();
},
2024-07-05 15:37:54 +00:00
),
2024-05-25 09:21:27 +00:00
);
},
),
separatorBuilder: (_, __) => const Divider(thickness: 0.3, height: 0.3),
);
}
}
class PostListEntryWidget extends StatelessWidget {
final bool isShowEmbed;
final bool isNestedClickable;
final bool isClickable;
final Post item;
final Function onUpdate;
const PostListEntryWidget({
super.key,
required this.isShowEmbed,
required this.isNestedClickable,
required this.isClickable,
required this.item,
required this.onUpdate,
});
@override
Widget build(BuildContext context) {
return GestureDetector(
child: PostItem(
key: Key('p${item.alias}'),
item: item,
isShowEmbed: isShowEmbed,
isClickable: isNestedClickable,
).paddingSymmetric(vertical: 8),
onTap: () {
if (!isClickable) return;
AppRouter.instance.pushNamed(
'postDetail',
pathParameters: {'alias': item.alias},
);
},
onLongPress: () {
showModalBottomSheet(
useRootNavigator: true,
context: context,
builder: (context) => PostAction(item: item),
).then((value) {
if (value != null) onUpdate();
});
},
);
}
}