fix(open-page-builders): add separate builders for each screen

This commit is contained in:
FahadFahim71 2024-03-14 16:40:57 +05:00
parent 27e3c34b96
commit a1ecb58dca
9 changed files with 104 additions and 51 deletions

View file

@ -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

View file

@ -42,22 +42,22 @@ List<GoRoute> getTimelineStoryRoutes({
postWidgetBuilder: config.postWidgetBuilder,
);
return buildScreenWithoutTransition(
context: context,
state: state,
child: config.openPageBuilder?.call(
context,
timelineScreen,
) ??
Scaffold(
appBar: AppBar(),
body: timelineScreen,
floatingActionButton: FloatingActionButton(
var button = FloatingActionButton(
onPressed: () async => context.go(
TimelineUserStoryRoutes.timelinePostCreation,
),
child: const Icon(Icons.add),
),
);
return buildScreenWithoutTransition(
context: context,
state: state,
child: config.homeOpenPageBuilder
?.call(context, timelineScreen, button) ??
Scaffold(
appBar: AppBar(),
body: timelineScreen,
floatingActionButton: button,
),
);
},
@ -77,20 +77,19 @@ List<GoRoute> 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<GoRoute> 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<GoRoute> 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<GoRoute> getTimelineStoryRoutes({
return buildScreenWithoutTransition(
context: context,
state: state,
child: config.openPageBuilder?.call(
child: config.postOverviewOpenPageBuilder?.call(
context,
timelinePostOverviewWidget,
) ??

View file

@ -144,13 +144,28 @@ Widget _postCreationScreenRoute({
onPostCreated: (post) async {
await config.service.postService.createPost(post);
if (context.mounted) {
if (config.afterPostCreationGoHome) {
await Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) =>
_timelineScreenRoute(configuration: config, context: context),
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 {

View file

@ -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;

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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,
),
),

View file

@ -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