feat: add getter for the userId in the timeline userstory configuration

This commit is contained in:
Freek van de Ven 2024-05-10 09:20:43 +02:00
parent 933386623a
commit deaca5b126
4 changed files with 11 additions and 6 deletions

View file

@ -2,6 +2,7 @@
- Add a serviceBuilder to the userstory configuration - 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 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 ## 3.0.1

View file

@ -30,7 +30,7 @@ List<GoRoute> getTimelineStoryRoutes({
pageBuilder: (context, state) { pageBuilder: (context, state) {
var service = config.serviceBuilder?.call(context) ?? config.service; var service = config.serviceBuilder?.call(context) ?? config.service;
var timelineScreen = TimelineScreen( var timelineScreen = TimelineScreen(
userId: config.userId, userId: config.getUserId?.call(context) ?? config.userId,
onUserTap: (user) => config.onUserTap?.call(context, user), onUserTap: (user) => config.onUserTap?.call(context, user),
service: service, service: service,
options: config.optionsBuilder(context), options: config.optionsBuilder(context),
@ -134,7 +134,7 @@ List<GoRoute> getTimelineStoryRoutes({
var post = service.postService.getPost(state.pathParameters['post']!); var post = service.postService.getPost(state.pathParameters['post']!);
var timelinePostWidget = TimelinePostScreen( var timelinePostWidget = TimelinePostScreen(
userId: config.userId, userId: config.getUserId?.call(context) ?? config.userId,
options: config.optionsBuilder(context), options: config.optionsBuilder(context),
service: service, service: service,
post: post!, post: post!,
@ -177,7 +177,7 @@ List<GoRoute> getTimelineStoryRoutes({
var category = state.pathParameters['category']; var category = state.pathParameters['category'];
var service = config.serviceBuilder?.call(context) ?? config.service; var service = config.serviceBuilder?.call(context) ?? config.service;
var timelinePostCreationWidget = TimelinePostCreationScreen( var timelinePostCreationWidget = TimelinePostCreationScreen(
userId: config.userId, userId: config.getUserId?.call(context) ?? config.userId,
options: config.optionsBuilder(context), options: config.optionsBuilder(context),
service: service, service: service,
onPostCreated: (post) async { onPostCreated: (post) async {

View file

@ -45,7 +45,7 @@ Widget _timelineScreenRoute({
); );
var timelineScreen = TimelineScreen( var timelineScreen = TimelineScreen(
userId: config.userId, userId: config.getUserId?.call(context) ?? config.userId,
onUserTap: (user) => config.onUserTap?.call(context, user), onUserTap: (user) => config.onUserTap?.call(context, user),
service: config.service, service: config.service,
options: config.optionsBuilder(context), options: config.optionsBuilder(context),
@ -121,7 +121,7 @@ Widget _postDetailScreenRoute({
); );
var timelinePostScreen = TimelinePostScreen( var timelinePostScreen = TimelinePostScreen(
userId: config.userId, userId: config.getUserId?.call(context) ?? config.userId,
options: config.optionsBuilder(context), options: config.optionsBuilder(context),
service: config.service, service: config.service,
post: post, post: post,
@ -176,7 +176,7 @@ Widget _postCreationScreenRoute({
); );
var timelinePostCreationScreen = TimelinePostCreationScreen( var timelinePostCreationScreen = TimelinePostCreationScreen(
userId: config.userId, userId: config.getUserId?.call(context) ?? config.userId,
options: config.optionsBuilder(context), options: config.optionsBuilder(context),
service: config.service, service: config.service,
onPostCreated: (post) async { onPostCreated: (post) async {

View file

@ -48,6 +48,7 @@ class TimelineUserStoryConfiguration {
const TimelineUserStoryConfiguration({ const TimelineUserStoryConfiguration({
required this.service, required this.service,
required this.optionsBuilder, required this.optionsBuilder,
this.getUserId,
this.serviceBuilder, this.serviceBuilder,
this.userId = 'test_user', this.userId = 'test_user',
this.homeOpenPageBuilder, this.homeOpenPageBuilder,
@ -67,6 +68,9 @@ class TimelineUserStoryConfiguration {
/// The ID of the user associated with this user story configuration. /// The ID of the user associated with this user story configuration.
final String userId; 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. /// The TimelineService responsible for fetching user story data.
final TimelineService service; final TimelineService service;