From 7fa33cdfb493acb73d7213bae451bd6b2196bd28 Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Tue, 21 May 2024 07:23:49 +0200 Subject: [PATCH] feat: add a post and category to the postViewOpenPageBuilder --- CHANGELOG.md | 1 + .../src/flutter_timeline_gorouter_userstory.dart | 13 +++++++++++-- .../src/flutter_timeline_navigator_userstory.dart | 9 ++++++++- .../lib/src/models/timeline_configuration.dart | 2 ++ packages/flutter_timeline/pubspec.yaml | 2 ++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd4b83d..d16c78c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fix the timelinecategory selection by removing the categories with key null - Set an optional max length on the default post title input field - Add a postCreationFloatingActionButtonColor to the timeline theme to set the color of the floating action button +- Add a post and a category to the postViewOpenPageBuilder function ## 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 91b238c..0b6da31 100644 --- a/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart +++ b/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart @@ -2,6 +2,7 @@ // // SPDX-License-Identifier: BSD-3-Clause +import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:flutter_timeline/flutter_timeline.dart'; import 'package:flutter_timeline/src/go_router.dart'; @@ -136,6 +137,14 @@ List getTimelineStoryRoutes({ pageBuilder: (context, state) { var service = config.serviceBuilder?.call(context) ?? config.service; var post = service.postService.getPost(state.pathParameters['post']!); + var category = config.optionsBuilder + .call(context) + .categoriesOptions + .categoriesBuilder + ?.call(context) + .firstWhereOrNull( + (element) => element.key == post?.category, + ); var timelinePostWidget = TimelinePostScreen( userId: config.getUserId?.call(context) ?? config.userId, @@ -155,8 +164,8 @@ List getTimelineStoryRoutes({ return buildScreenWithoutTransition( context: context, state: state, - child: config.postViewOpenPageBuilder - ?.call(context, timelinePostWidget, backButton) ?? + child: config.postViewOpenPageBuilder?.call( + context, timelinePostWidget, backButton, post, category) ?? Scaffold( appBar: AppBar( leading: backButton, 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 b8f6d00..802876f 100644 --- a/packages/flutter_timeline/lib/src/flutter_timeline_navigator_userstory.dart +++ b/packages/flutter_timeline/lib/src/flutter_timeline_navigator_userstory.dart @@ -135,6 +135,13 @@ Widget _postDetailScreenRoute({ onUserTap: (user) => config.onUserTap?.call(context, user), ); + var category = config + .optionsBuilder(context) + .categoriesOptions + .categoriesBuilder + ?.call(context) + .firstWhere((element) => element.key == post.category); + var backButton = IconButton( color: Colors.white, icon: const Icon(Icons.arrow_back_ios), @@ -142,7 +149,7 @@ Widget _postDetailScreenRoute({ ); return config.postViewOpenPageBuilder - ?.call(context, timelinePostScreen, backButton) ?? + ?.call(context, timelinePostScreen, backButton, post, category) ?? Scaffold( appBar: AppBar( leading: backButton, diff --git a/packages/flutter_timeline/lib/src/models/timeline_configuration.dart b/packages/flutter_timeline/lib/src/models/timeline_configuration.dart index 81938be..dffadeb 100644 --- a/packages/flutter_timeline/lib/src/models/timeline_configuration.dart +++ b/packages/flutter_timeline/lib/src/models/timeline_configuration.dart @@ -108,6 +108,8 @@ class TimelineUserStoryConfiguration { BuildContext context, Widget child, IconButton? button, + TimelinePost post, + TimelineCategory? category, )? postViewOpenPageBuilder; /// Open page builder function for the post overview page. This function diff --git a/packages/flutter_timeline/pubspec.yaml b/packages/flutter_timeline/pubspec.yaml index ecb9108..46c77ba 100644 --- a/packages/flutter_timeline/pubspec.yaml +++ b/packages/flutter_timeline/pubspec.yaml @@ -15,6 +15,8 @@ dependencies: sdk: flutter go_router: any + collection: any + flutter_timeline_view: git: url: https://github.com/Iconica-Development/flutter_timeline