From deaca5b1269849ba0ffbf4bc18691fb06e663f3d Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Fri, 10 May 2024 09:20:43 +0200 Subject: [PATCH] feat: add getter for the userId in the timeline userstory configuration --- CHANGELOG.md | 1 + .../lib/src/flutter_timeline_gorouter_userstory.dart | 6 +++--- .../lib/src/flutter_timeline_navigator_userstory.dart | 6 +++--- .../lib/src/models/timeline_configuration.dart | 4 ++++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a61398b..7ff63f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Add a serviceBuilder to the userstory configuration - Add a listHeaderBuilder for showing a header at the top of the list of posts in the timeline +- Add a getUserId function to retrieve the userId when needed in the userstory configuration ## 3.0.1 diff --git a/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart b/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart index c1c68db..fba23b9 100644 --- a/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart +++ b/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart @@ -30,7 +30,7 @@ List getTimelineStoryRoutes({ pageBuilder: (context, state) { var service = config.serviceBuilder?.call(context) ?? config.service; var timelineScreen = TimelineScreen( - userId: config.userId, + userId: config.getUserId?.call(context) ?? config.userId, onUserTap: (user) => config.onUserTap?.call(context, user), service: service, options: config.optionsBuilder(context), @@ -134,7 +134,7 @@ List getTimelineStoryRoutes({ var post = service.postService.getPost(state.pathParameters['post']!); var timelinePostWidget = TimelinePostScreen( - userId: config.userId, + userId: config.getUserId?.call(context) ?? config.userId, options: config.optionsBuilder(context), service: service, post: post!, @@ -177,7 +177,7 @@ List getTimelineStoryRoutes({ var category = state.pathParameters['category']; var service = config.serviceBuilder?.call(context) ?? config.service; var timelinePostCreationWidget = TimelinePostCreationScreen( - userId: config.userId, + userId: config.getUserId?.call(context) ?? config.userId, options: config.optionsBuilder(context), service: service, onPostCreated: (post) async { diff --git a/packages/flutter_timeline/lib/src/flutter_timeline_navigator_userstory.dart b/packages/flutter_timeline/lib/src/flutter_timeline_navigator_userstory.dart index da9325a..90465e4 100644 --- a/packages/flutter_timeline/lib/src/flutter_timeline_navigator_userstory.dart +++ b/packages/flutter_timeline/lib/src/flutter_timeline_navigator_userstory.dart @@ -45,7 +45,7 @@ Widget _timelineScreenRoute({ ); var timelineScreen = TimelineScreen( - userId: config.userId, + userId: config.getUserId?.call(context) ?? config.userId, onUserTap: (user) => config.onUserTap?.call(context, user), service: config.service, options: config.optionsBuilder(context), @@ -121,7 +121,7 @@ Widget _postDetailScreenRoute({ ); var timelinePostScreen = TimelinePostScreen( - userId: config.userId, + userId: config.getUserId?.call(context) ?? config.userId, options: config.optionsBuilder(context), service: config.service, post: post, @@ -176,7 +176,7 @@ Widget _postCreationScreenRoute({ ); var timelinePostCreationScreen = TimelinePostCreationScreen( - userId: config.userId, + userId: config.getUserId?.call(context) ?? config.userId, options: config.optionsBuilder(context), service: config.service, onPostCreated: (post) async { diff --git a/packages/flutter_timeline/lib/src/models/timeline_configuration.dart b/packages/flutter_timeline/lib/src/models/timeline_configuration.dart index 8ce93cf..81938be 100644 --- a/packages/flutter_timeline/lib/src/models/timeline_configuration.dart +++ b/packages/flutter_timeline/lib/src/models/timeline_configuration.dart @@ -48,6 +48,7 @@ class TimelineUserStoryConfiguration { const TimelineUserStoryConfiguration({ required this.service, required this.optionsBuilder, + this.getUserId, this.serviceBuilder, this.userId = 'test_user', this.homeOpenPageBuilder, @@ -67,6 +68,9 @@ class TimelineUserStoryConfiguration { /// The ID of the user associated with this user story configuration. final String userId; + /// A function to get the userId only when needed and with a context + final String Function(BuildContext context)? getUserId; + /// The TimelineService responsible for fetching user story data. final TimelineService service;