mirror of
https://github.com/Iconica-Development/flutter_timeline.git
synced 2025-05-19 02:23:46 +02:00
feat: add serviceBuilder for userstory configuration to fetch the service when needed
This commit is contained in:
parent
93a74fb904
commit
4f7fa834e4
7 changed files with 36 additions and 27 deletions
|
@ -1,3 +1,8 @@
|
|||
## 4.0.0
|
||||
|
||||
- Add a serviceBuilder to the userstory configuration
|
||||
|
||||
|
||||
## 3.0.1
|
||||
|
||||
- Fixed postOverviewScreen not displaying the creators name.
|
||||
|
|
|
@ -28,10 +28,11 @@ List<GoRoute> 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<GoRoute> 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<GoRoute> 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<GoRoute> 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(
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue