mirror of
https://github.com/Iconica-Development/flutter_timeline.git
synced 2025-05-18 18:13:46 +02:00
fix: remove allowAllDeletion from the options and add it to the userstory
This commit is contained in:
parent
aa22e1305b
commit
71645eee3b
9 changed files with 34 additions and 13 deletions
|
@ -21,6 +21,7 @@
|
|||
- Change the CategorySelectorButton to use more styling options and allow for an icon to be shown
|
||||
- Fix incorrect timeline reaction name
|
||||
- Add a dialog for post deletion confirmation
|
||||
- Add a callback method to determine if a user can delete posts that gets called when needed
|
||||
|
||||
## 3.0.1
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ TimelineUserStoryConfiguration getConfig(TimelineService service) {
|
|||
userId: 'test_user',
|
||||
optionsBuilder: (context) => options,
|
||||
enablePostOverviewScreen: false,
|
||||
canDeleteAllPosts: (_) => true,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -15,7 +16,6 @@ var options = TimelineOptions(
|
|||
paddings: TimelinePaddingOptions(
|
||||
mainPadding: const EdgeInsets.all(20).copyWith(top: 28),
|
||||
),
|
||||
allowAllDeletion: true,
|
||||
categoriesOptions: CategoriesOptions(
|
||||
categoriesBuilder: (context) => [
|
||||
const TimelineCategory(
|
||||
|
|
|
@ -33,6 +33,7 @@ List<GoRoute> getTimelineStoryRoutes({
|
|||
var timelineScreen = TimelineScreen(
|
||||
userId: config.getUserId?.call(context) ?? config.userId,
|
||||
onUserTap: (user) => config.onUserTap?.call(context, user),
|
||||
allowAllDeletion: config.canDeleteAllPosts?.call(context) ?? false,
|
||||
onRefresh: config.onRefresh,
|
||||
service: service,
|
||||
options: config.optionsBuilder(context),
|
||||
|
@ -151,6 +152,7 @@ List<GoRoute> getTimelineStoryRoutes({
|
|||
|
||||
var timelinePostWidget = TimelinePostScreen(
|
||||
userId: config.getUserId?.call(context) ?? config.userId,
|
||||
allowAllDeletion: config.canDeleteAllPosts?.call(context) ?? false,
|
||||
options: config.optionsBuilder(context),
|
||||
service: service,
|
||||
post: post!,
|
||||
|
|
|
@ -46,6 +46,7 @@ Widget _timelineScreenRoute({
|
|||
|
||||
var timelineScreen = TimelineScreen(
|
||||
userId: config.getUserId?.call(context) ?? config.userId,
|
||||
allowAllDeletion: config.canDeleteAllPosts?.call(context) ?? false,
|
||||
onUserTap: (user) => config.onUserTap?.call(context, user),
|
||||
service: config.service,
|
||||
options: config.optionsBuilder(context),
|
||||
|
@ -127,6 +128,7 @@ Widget _postDetailScreenRoute({
|
|||
|
||||
var timelinePostScreen = TimelinePostScreen(
|
||||
userId: config.getUserId?.call(context) ?? config.userId,
|
||||
allowAllDeletion: config.canDeleteAllPosts?.call(context) ?? false,
|
||||
options: config.optionsBuilder(context),
|
||||
service: config.service,
|
||||
post: post,
|
||||
|
|
|
@ -50,6 +50,7 @@ class TimelineUserStoryConfiguration {
|
|||
required this.optionsBuilder,
|
||||
this.getUserId,
|
||||
this.serviceBuilder,
|
||||
this.canDeleteAllPosts,
|
||||
this.userId = 'test_user',
|
||||
this.homeOpenPageBuilder,
|
||||
this.postCreationOpenPageBuilder,
|
||||
|
@ -72,6 +73,10 @@ class TimelineUserStoryConfiguration {
|
|||
/// A function to get the userId only when needed and with a context
|
||||
final String Function(BuildContext context)? getUserId;
|
||||
|
||||
/// A function to determine if a user can delete posts that is called
|
||||
/// when needed
|
||||
final bool Function(BuildContext context)? canDeleteAllPosts;
|
||||
|
||||
/// The TimelineService responsible for fetching user story data.
|
||||
final TimelineService service;
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ class TimelineOptions {
|
|||
this.imagePickerConfig = const ImagePickerConfig(),
|
||||
this.imagePickerTheme = const ImagePickerTheme(),
|
||||
this.timelinePostHeight,
|
||||
this.allowAllDeletion = false,
|
||||
this.sortCommentsAscending = true,
|
||||
this.sortPostsAscending,
|
||||
this.doubleTapTolike = false,
|
||||
|
@ -71,10 +70,6 @@ class TimelineOptions {
|
|||
/// Whether to sort posts ascending or descending
|
||||
final bool? sortPostsAscending;
|
||||
|
||||
/// Allow all posts to be deleted instead of
|
||||
/// only the posts of the current user
|
||||
final bool allowAllDeletion;
|
||||
|
||||
/// The height of a post in the timeline
|
||||
final double? timelinePostHeight;
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ class TimelinePostScreen extends StatefulWidget {
|
|||
required this.options,
|
||||
required this.post,
|
||||
required this.onPostDelete,
|
||||
this.allowAllDeletion = false,
|
||||
this.isOverviewScreen = false,
|
||||
this.onUserTap,
|
||||
super.key,
|
||||
|
@ -31,6 +32,10 @@ class TimelinePostScreen extends StatefulWidget {
|
|||
/// The user id of the current user
|
||||
final String userId;
|
||||
|
||||
/// Allow all posts to be deleted instead of
|
||||
/// only the posts of the current user
|
||||
final bool allowAllDeletion;
|
||||
|
||||
/// The timeline service to fetch the post details
|
||||
final TimelineService service;
|
||||
|
||||
|
@ -193,7 +198,7 @@ class _TimelinePostScreenState extends State<TimelinePostScreen> {
|
|||
),
|
||||
const Spacer(),
|
||||
if (!(widget.isOverviewScreen ?? false) &&
|
||||
(widget.options.allowAllDeletion ||
|
||||
(widget.allowAllDeletion ||
|
||||
post.creator?.userId == widget.userId))
|
||||
PopupMenuButton(
|
||||
onSelected: (value) async {
|
||||
|
@ -422,7 +427,7 @@ class _TimelinePostScreenState extends State<TimelinePostScreen> {
|
|||
GestureDetector(
|
||||
onLongPressStart: (details) async {
|
||||
if (reaction.creatorId == widget.userId ||
|
||||
widget.options.allowAllDeletion) {
|
||||
widget.allowAllDeletion) {
|
||||
var overlay = Overlay.of(context)
|
||||
.context
|
||||
.findRenderObject()! as RenderBox;
|
||||
|
|
|
@ -21,12 +21,17 @@ class TimelineScreen extends StatefulWidget {
|
|||
this.timelineCategory,
|
||||
this.postWidgetBuilder,
|
||||
this.filterEnabled = false,
|
||||
this.allowAllDeletion = false,
|
||||
super.key,
|
||||
});
|
||||
|
||||
/// The user id of the current user
|
||||
final String userId;
|
||||
|
||||
/// Allow all posts to be deleted instead of
|
||||
/// only the posts of the current user
|
||||
final bool allowAllDeletion;
|
||||
|
||||
/// The service to use for fetching and manipulating posts
|
||||
final TimelineService? service;
|
||||
|
||||
|
@ -151,10 +156,9 @@ class _TimelineScreenState extends State<TimelineScreen> {
|
|||
),
|
||||
if (widget.filterEnabled) ...[
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
// left: widget.options.padding.left,
|
||||
// right: widget.options.padding.right,
|
||||
horizontal: widget.options.paddings.mainPadding.horizontal,
|
||||
padding: EdgeInsets.only(
|
||||
left: widget.options.paddings.mainPadding.left,
|
||||
right: widget.options.paddings.mainPadding.right,
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
|
@ -246,6 +250,7 @@ class _TimelineScreenState extends State<TimelineScreen> {
|
|||
service: service,
|
||||
userId: widget.userId,
|
||||
options: widget.options,
|
||||
allowAllDeletion: widget.allowAllDeletion,
|
||||
post: post,
|
||||
onTap: () async {
|
||||
if (widget.onPostTap != null) {
|
||||
|
|
|
@ -18,12 +18,18 @@ class TimelinePostWidget extends StatefulWidget {
|
|||
required this.onTapUnlike,
|
||||
required this.onPostDelete,
|
||||
required this.service,
|
||||
required this.allowAllDeletion,
|
||||
this.onUserTap,
|
||||
super.key,
|
||||
});
|
||||
|
||||
/// The user id of the current user
|
||||
final String userId;
|
||||
|
||||
/// Allow all posts to be deleted instead of
|
||||
/// only the posts of the current user
|
||||
final bool allowAllDeletion;
|
||||
|
||||
final TimelineOptions options;
|
||||
|
||||
final TimelinePost post;
|
||||
|
@ -103,7 +109,7 @@ class _TimelinePostWidgetState extends State<TimelinePostWidget> {
|
|||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (widget.options.allowAllDeletion ||
|
||||
if (widget.allowAllDeletion ||
|
||||
widget.post.creator?.userId == widget.userId)
|
||||
PopupMenuButton(
|
||||
onSelected: (value) async {
|
||||
|
|
Loading…
Reference in a new issue