mirror of
https://github.com/Iconica-Development/flutter_timeline.git
synced 2025-05-19 10:33:44 +02:00
fix(open-page-builders): add separate builders for each screen
This commit is contained in:
parent
27e3c34b96
commit
7fd8179a07
9 changed files with 108 additions and 55 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
) ??
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -19,13 +19,13 @@ dependencies:
|
|||
git:
|
||||
url: https://github.com/Iconica-Development/flutter_timeline
|
||||
path: packages/flutter_timeline_view
|
||||
ref: 2.2.0
|
||||
ref: 2.3.0
|
||||
|
||||
flutter_timeline_interface:
|
||||
git:
|
||||
url: https://github.com/Iconica-Development/flutter_timeline
|
||||
path: packages/flutter_timeline_interface
|
||||
ref: 2.2.0
|
||||
ref: 2.3.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: 2.2.0
|
||||
version: 2.3.0
|
||||
|
||||
publish_to: none
|
||||
|
||||
|
@ -23,7 +23,7 @@ dependencies:
|
|||
git:
|
||||
url: https://github.com/Iconica-Development/flutter_timeline
|
||||
path: packages/flutter_timeline_interface
|
||||
ref: 2.2.0
|
||||
ref: 2.3.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: 2.2.0
|
||||
version: 2.3.0
|
||||
|
||||
publish_to: none
|
||||
|
||||
|
|
|
@ -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,
|
||||
),
|
||||
),
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -23,7 +23,7 @@ dependencies:
|
|||
git:
|
||||
url: https://github.com/Iconica-Development/flutter_timeline
|
||||
path: packages/flutter_timeline_interface
|
||||
ref: 2.2.0
|
||||
ref: 2.3.0
|
||||
flutter_image_picker:
|
||||
git:
|
||||
url: https://github.com/Iconica-Development/flutter_image_picker
|
||||
|
|
Loading…
Reference in a new issue