diff --git a/CHANGELOG.md b/CHANGELOG.md index 61ef9cf..9bee2c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 4.0.0 + +- Add a serviceBuilder to the userstory configuration + + ## 3.0.1 - Fixed postOverviewScreen not displaying the creators name. 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 41e68fc..c1c68db 100644 --- a/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart +++ b/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart @@ -28,10 +28,11 @@ List getTimelineStoryRoutes({ GoRoute( path: TimelineUserStoryRoutes.timelineHome, pageBuilder: (context, state) { + var service = config.serviceBuilder?.call(context) ?? config.service; var timelineScreen = TimelineScreen( userId: config.userId, onUserTap: (user) => config.onUserTap?.call(context, user), - service: config.service, + service: service, options: config.optionsBuilder(context), onPostTap: (post) async => config.onPostTap?.call(context, post) ?? @@ -129,13 +130,13 @@ List getTimelineStoryRoutes({ GoRoute( path: TimelineUserStoryRoutes.timelineView, pageBuilder: (context, state) { - var post = - config.service.postService.getPost(state.pathParameters['post']!); + var service = config.serviceBuilder?.call(context) ?? config.service; + var post = service.postService.getPost(state.pathParameters['post']!); var timelinePostWidget = TimelinePostScreen( userId: config.userId, options: config.optionsBuilder(context), - service: config.service, + service: service, post: post!, onPostDelete: () => config.onPostDelete?.call(context, post), onUserTap: (user) => config.onUserTap?.call(context, user), @@ -174,19 +175,19 @@ List getTimelineStoryRoutes({ path: TimelineUserStoryRoutes.timelinePostCreation, pageBuilder: (context, state) { var category = state.pathParameters['category']; + var service = config.serviceBuilder?.call(context) ?? config.service; var timelinePostCreationWidget = TimelinePostCreationScreen( userId: config.userId, options: config.optionsBuilder(context), - service: config.service, + service: service, onPostCreated: (post) async { - var newPost = await config.service.postService.createPost(post); - if (context.mounted) { - if (config.afterPostCreationGoHome) { - context.go(TimelineUserStoryRoutes.timelineHome); - } else { - await context - .push(TimelineUserStoryRoutes.timelineViewPath(newPost.id)); - } + var newPost = await service.postService.createPost(post); + if (!context.mounted) return; + if (config.afterPostCreationGoHome) { + context.go(TimelineUserStoryRoutes.timelineHome); + } else { + await context + .push(TimelineUserStoryRoutes.timelineViewPath(newPost.id)); } }, onPostOverview: (post) async => context.push( @@ -233,16 +234,15 @@ List getTimelineStoryRoutes({ path: TimelineUserStoryRoutes.timelinePostOverview, pageBuilder: (context, state) { var post = state.extra! as TimelinePost; - + var service = config.serviceBuilder?.call(context) ?? config.service; var timelinePostOverviewWidget = TimelinePostOverviewScreen( options: config.optionsBuilder(context), - service: config.service, + service: service, timelinePost: post, onPostSubmit: (post) async { - await config.service.postService.createPost(post); - if (context.mounted) { - context.go(TimelineUserStoryRoutes.timelineHome); - } + await service.postService.createPost(post); + if (!context.mounted) return; + context.go(TimelineUserStoryRoutes.timelineHome); }, ); var backButton = IconButton( diff --git a/packages/flutter_timeline/lib/src/models/timeline_configuration.dart b/packages/flutter_timeline/lib/src/models/timeline_configuration.dart index 264be11..8ce93cf 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.serviceBuilder, this.userId = 'test_user', this.homeOpenPageBuilder, this.postCreationOpenPageBuilder, @@ -69,6 +70,9 @@ class TimelineUserStoryConfiguration { /// The TimelineService responsible for fetching user story data. final TimelineService service; + /// A function to get the timeline service only when needed and with a context + final TimelineService Function(BuildContext context)? serviceBuilder; + /// A function that builds TimelineOptions based on the given BuildContext. final TimelineOptions Function(BuildContext context) optionsBuilder; diff --git a/packages/flutter_timeline/pubspec.yaml b/packages/flutter_timeline/pubspec.yaml index bfa62ef..ecb9108 100644 --- a/packages/flutter_timeline/pubspec.yaml +++ b/packages/flutter_timeline/pubspec.yaml @@ -3,7 +3,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later name: flutter_timeline description: Visual elements and interface combined into one package -version: 3.0.1 +version: 4.0.0 publish_to: none @@ -19,13 +19,13 @@ dependencies: git: url: https://github.com/Iconica-Development/flutter_timeline path: packages/flutter_timeline_view - ref: 3.0.1 + ref: 4.0.0 flutter_timeline_interface: git: url: https://github.com/Iconica-Development/flutter_timeline path: packages/flutter_timeline_interface - ref: 3.0.1 + ref: 4.0.0 dev_dependencies: flutter_lints: ^2.0.0 diff --git a/packages/flutter_timeline_firebase/pubspec.yaml b/packages/flutter_timeline_firebase/pubspec.yaml index 3b670d5..89ad8a8 100644 --- a/packages/flutter_timeline_firebase/pubspec.yaml +++ b/packages/flutter_timeline_firebase/pubspec.yaml @@ -4,7 +4,7 @@ name: flutter_timeline_firebase description: Implementation of the Flutter Timeline interface for Firebase. -version: 3.0.1 +version: 4.0.0 publish_to: none @@ -23,7 +23,7 @@ dependencies: git: url: https://github.com/Iconica-Development/flutter_timeline path: packages/flutter_timeline_interface - ref: 3.0.1 + ref: 4.0.0 dev_dependencies: flutter_lints: ^2.0.0 diff --git a/packages/flutter_timeline_interface/pubspec.yaml b/packages/flutter_timeline_interface/pubspec.yaml index 3960249..6e0fc04 100644 --- a/packages/flutter_timeline_interface/pubspec.yaml +++ b/packages/flutter_timeline_interface/pubspec.yaml @@ -4,7 +4,7 @@ name: flutter_timeline_interface description: Interface for the service of the Flutter Timeline component -version: 3.0.1 +version: 4.0.0 publish_to: none diff --git a/packages/flutter_timeline_view/pubspec.yaml b/packages/flutter_timeline_view/pubspec.yaml index 48f76bf..35f0c84 100644 --- a/packages/flutter_timeline_view/pubspec.yaml +++ b/packages/flutter_timeline_view/pubspec.yaml @@ -4,7 +4,7 @@ name: flutter_timeline_view description: Visual elements of the Flutter Timeline Component -version: 3.0.1 +version: 4.0.0 publish_to: none @@ -23,7 +23,7 @@ dependencies: git: url: https://github.com/Iconica-Development/flutter_timeline path: packages/flutter_timeline_interface - ref: 3.0.1 + ref: 4.0.0 flutter_image_picker: git: url: https://github.com/Iconica-Development/flutter_image_picker