diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e69a20..0f00d77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.3.0 + +- Added separate open page builders for timeline screens +- Fixed afterPostCreationGoHome routing in gorouter and navigater user stories + ## 2.2.0 - Add all routes to gorouter and navigator user stories 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 91f49f9..dc30f03 100644 --- a/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart +++ b/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart @@ -42,22 +42,22 @@ List getTimelineStoryRoutes({ postWidgetBuilder: config.postWidgetBuilder, ); + var button = FloatingActionButton( + onPressed: () async => context.go( + TimelineUserStoryRoutes.timelinePostCreation, + ), + child: const Icon(Icons.add), + ); + return buildScreenWithoutTransition( context: context, state: state, - child: config.openPageBuilder?.call( - context, - timelineScreen, - ) ?? + child: config.homeOpenPageBuilder + ?.call(context, timelineScreen, button) ?? Scaffold( appBar: AppBar(), body: timelineScreen, - floatingActionButton: FloatingActionButton( - onPressed: () async => context.go( - TimelineUserStoryRoutes.timelinePostCreation, - ), - child: const Icon(Icons.add), - ), + floatingActionButton: button, ), ); }, @@ -77,20 +77,19 @@ List getTimelineStoryRoutes({ onUserTap: (user) => config.onUserTap?.call(context, user), ); + var backButton = IconButton( + icon: const Icon(Icons.arrow_back_ios), + onPressed: () => context.go(TimelineUserStoryRoutes.timelineHome), + ); + return buildScreenWithoutTransition( context: context, state: state, - child: config.openPageBuilder?.call( - context, - timelinePostWidget, - ) ?? + child: config.postViewOpenPageBuilder + ?.call(context, timelinePostWidget, backButton) ?? Scaffold( appBar: AppBar( - leading: IconButton( - icon: const Icon(Icons.arrow_back_ios), - onPressed: () => - context.go(TimelineUserStoryRoutes.timelineHome), - ), + leading: backButton, ), body: timelinePostWidget, ), @@ -105,15 +104,13 @@ List getTimelineStoryRoutes({ options: config.optionsBuilder(context), service: config.service, onPostCreated: (post) async { - await config.service.postService.createPost(post); + var newPost = await config.service.postService.createPost(post); if (context.mounted) { if (config.afterPostCreationGoHome) { context.go(TimelineUserStoryRoutes.timelineHome); } else { - context.go( - TimelineUserStoryRoutes.timelinePostOverview, - extra: post, - ); + await context + .push(TimelineUserStoryRoutes.timelineViewPath(newPost.id)); } } }, @@ -124,23 +121,22 @@ List getTimelineStoryRoutes({ enablePostOverviewScreen: config.enablePostOverviewScreen, ); + var backButton = IconButton( + icon: const Icon(Icons.arrow_back_ios), + onPressed: () => context.go(TimelineUserStoryRoutes.timelineHome), + ); + return buildScreenWithoutTransition( context: context, state: state, - child: config.openPageBuilder?.call( - context, - timelinePostCreationWidget, - ) ?? + child: config.postCreationOpenPageBuilder + ?.call(context, timelinePostCreationWidget, backButton) ?? Scaffold( appBar: AppBar( title: Text( config.optionsBuilder(context).translations.postCreation, ), - leading: IconButton( - icon: const Icon(Icons.arrow_back_ios), - onPressed: () => - context.go(TimelineUserStoryRoutes.timelineHome), - ), + leading: backButton, ), body: timelinePostCreationWidget, ), @@ -167,7 +163,7 @@ List getTimelineStoryRoutes({ return buildScreenWithoutTransition( context: context, state: state, - child: config.openPageBuilder?.call( + child: config.postOverviewOpenPageBuilder?.call( context, timelinePostOverviewWidget, ) ?? 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 70fe59f..9398f1a 100644 --- a/packages/flutter_timeline/lib/src/flutter_timeline_navigator_userstory.dart +++ b/packages/flutter_timeline/lib/src/flutter_timeline_navigator_userstory.dart @@ -144,13 +144,28 @@ Widget _postCreationScreenRoute({ onPostCreated: (post) async { await config.service.postService.createPost(post); if (context.mounted) { - await Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (context) => - _timelineScreenRoute(configuration: config, context: context), - ), - ); + if (config.afterPostCreationGoHome) { + await Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (context) => _timelineScreenRoute( + configuration: config, + context: context, + ), + ), + ); + } else { + await Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (context) => _postDetailScreenRoute( + configuration: config, + context: context, + post: post, + ), + ), + ); + } } }, onPostOverview: (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 669afe5..bec248d 100644 --- a/packages/flutter_timeline/lib/src/models/timeline_configuration.dart +++ b/packages/flutter_timeline/lib/src/models/timeline_configuration.dart @@ -49,7 +49,10 @@ class TimelineUserStoryConfiguration { required this.service, required this.optionsBuilder, this.userId = 'test_user', - this.openPageBuilder, + this.homeOpenPageBuilder, + this.postCreationOpenPageBuilder, + this.postViewOpenPageBuilder, + this.postOverviewOpenPageBuilder, this.onPostTap, this.onUserTap, this.onPostDelete, @@ -68,8 +71,44 @@ class TimelineUserStoryConfiguration { /// A function that builds TimelineOptions based on the given BuildContext. final TimelineOptions Function(BuildContext context) optionsBuilder; - /// A function that defines the behavior when a page needs to be opened. - final Function(BuildContext context, Widget child)? openPageBuilder; + /// Open page builder function for the home page. This function accepts + /// a [BuildContext], a child widget, and a FloatingActionButton which can + /// route to the post creation page. + + final Function( + BuildContext context, + Widget child, + FloatingActionButton? button, + )? homeOpenPageBuilder; + + /// Open page builder function for the post creation page. This function + /// accepts a [BuildContext], a child widget, and an IconButton which can + /// route to the home page. + + final Function( + BuildContext context, + Widget child, + IconButton? button, + )? postCreationOpenPageBuilder; + + /// Open page builder function for the post view page. This function accepts + /// a [BuildContext], a child widget, and an IconButton which can route to the + /// home page. + + final Function( + BuildContext context, + Widget child, + IconButton? button, + )? postViewOpenPageBuilder; + + /// Open page builder function for the post overview page. This function + /// accepts a [BuildContext], a child widget, and an IconButton which can + /// route to the home page. + + final Function( + BuildContext context, + Widget child, + )? postOverviewOpenPageBuilder; /// A callback function invoked when a timeline post is tapped. final Function(BuildContext context, TimelinePost post)? onPostTap; diff --git a/packages/flutter_timeline/pubspec.yaml b/packages/flutter_timeline/pubspec.yaml index 79f4d2e..93512ff 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: 2.2.0 +version: 2.3.0 publish_to: none diff --git a/packages/flutter_timeline_firebase/pubspec.yaml b/packages/flutter_timeline_firebase/pubspec.yaml index e2efec0..917addd 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: 2.2.0 +version: 2.3.0 publish_to: none diff --git a/packages/flutter_timeline_interface/pubspec.yaml b/packages/flutter_timeline_interface/pubspec.yaml index 1c92612..d91da84 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: 2.2.0 +version: 2.3.0 publish_to: none diff --git a/packages/flutter_timeline_view/lib/src/screens/timeline_post_overview_screen.dart b/packages/flutter_timeline_view/lib/src/screens/timeline_post_overview_screen.dart index bb30a3d..0f75694 100644 --- a/packages/flutter_timeline_view/lib/src/screens/timeline_post_overview_screen.dart +++ b/packages/flutter_timeline_view/lib/src/screens/timeline_post_overview_screen.dart @@ -30,9 +30,7 @@ class TimelinePostOverviewScreen extends StatelessWidget { userId: timelinePost.creatorId, options: options, post: timelinePost, - onPostDelete: () async { - await service.postService.deletePost(timelinePost); - }, + onPostDelete: () async {}, service: service, ), ), diff --git a/packages/flutter_timeline_view/pubspec.yaml b/packages/flutter_timeline_view/pubspec.yaml index 13dfc71..34d17e8 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: 2.2.0 +version: 2.3.0 publish_to: none