Merge pull request #31 from Iconica-Development/2.3.0

fix(open-page-builders): add separate builders for each screen
This commit is contained in:
Gorter-dev 2024-03-15 15:31:40 +01:00 committed by GitHub
commit 1ce80135f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 108 additions and 55 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 ## 2.2.0
- Add all routes to gorouter and navigator user stories - Add all routes to gorouter and navigator user stories

View file

@ -42,22 +42,22 @@ List<GoRoute> getTimelineStoryRoutes({
postWidgetBuilder: config.postWidgetBuilder, postWidgetBuilder: config.postWidgetBuilder,
); );
var button = FloatingActionButton(
onPressed: () async => context.go(
TimelineUserStoryRoutes.timelinePostCreation,
),
child: const Icon(Icons.add),
);
return buildScreenWithoutTransition( return buildScreenWithoutTransition(
context: context, context: context,
state: state, state: state,
child: config.openPageBuilder?.call( child: config.homeOpenPageBuilder
context, ?.call(context, timelineScreen, button) ??
timelineScreen,
) ??
Scaffold( Scaffold(
appBar: AppBar(), appBar: AppBar(),
body: timelineScreen, body: timelineScreen,
floatingActionButton: FloatingActionButton( floatingActionButton: button,
onPressed: () async => context.go(
TimelineUserStoryRoutes.timelinePostCreation,
),
child: const Icon(Icons.add),
),
), ),
); );
}, },
@ -77,20 +77,19 @@ List<GoRoute> getTimelineStoryRoutes({
onUserTap: (user) => config.onUserTap?.call(context, user), onUserTap: (user) => config.onUserTap?.call(context, user),
); );
var backButton = IconButton(
icon: const Icon(Icons.arrow_back_ios),
onPressed: () => context.go(TimelineUserStoryRoutes.timelineHome),
);
return buildScreenWithoutTransition( return buildScreenWithoutTransition(
context: context, context: context,
state: state, state: state,
child: config.openPageBuilder?.call( child: config.postViewOpenPageBuilder
context, ?.call(context, timelinePostWidget, backButton) ??
timelinePostWidget,
) ??
Scaffold( Scaffold(
appBar: AppBar( appBar: AppBar(
leading: IconButton( leading: backButton,
icon: const Icon(Icons.arrow_back_ios),
onPressed: () =>
context.go(TimelineUserStoryRoutes.timelineHome),
),
), ),
body: timelinePostWidget, body: timelinePostWidget,
), ),
@ -105,15 +104,13 @@ List<GoRoute> getTimelineStoryRoutes({
options: config.optionsBuilder(context), options: config.optionsBuilder(context),
service: config.service, service: config.service,
onPostCreated: (post) async { onPostCreated: (post) async {
await config.service.postService.createPost(post); var newPost = await config.service.postService.createPost(post);
if (context.mounted) { if (context.mounted) {
if (config.afterPostCreationGoHome) { if (config.afterPostCreationGoHome) {
context.go(TimelineUserStoryRoutes.timelineHome); context.go(TimelineUserStoryRoutes.timelineHome);
} else { } else {
context.go( await context
TimelineUserStoryRoutes.timelinePostOverview, .push(TimelineUserStoryRoutes.timelineViewPath(newPost.id));
extra: post,
);
} }
} }
}, },
@ -124,23 +121,22 @@ List<GoRoute> getTimelineStoryRoutes({
enablePostOverviewScreen: config.enablePostOverviewScreen, enablePostOverviewScreen: config.enablePostOverviewScreen,
); );
var backButton = IconButton(
icon: const Icon(Icons.arrow_back_ios),
onPressed: () => context.go(TimelineUserStoryRoutes.timelineHome),
);
return buildScreenWithoutTransition( return buildScreenWithoutTransition(
context: context, context: context,
state: state, state: state,
child: config.openPageBuilder?.call( child: config.postCreationOpenPageBuilder
context, ?.call(context, timelinePostCreationWidget, backButton) ??
timelinePostCreationWidget,
) ??
Scaffold( Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text( title: Text(
config.optionsBuilder(context).translations.postCreation, config.optionsBuilder(context).translations.postCreation,
), ),
leading: IconButton( leading: backButton,
icon: const Icon(Icons.arrow_back_ios),
onPressed: () =>
context.go(TimelineUserStoryRoutes.timelineHome),
),
), ),
body: timelinePostCreationWidget, body: timelinePostCreationWidget,
), ),
@ -167,7 +163,7 @@ List<GoRoute> getTimelineStoryRoutes({
return buildScreenWithoutTransition( return buildScreenWithoutTransition(
context: context, context: context,
state: state, state: state,
child: config.openPageBuilder?.call( child: config.postOverviewOpenPageBuilder?.call(
context, context,
timelinePostOverviewWidget, timelinePostOverviewWidget,
) ?? ) ??

View file

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

View file

@ -49,7 +49,10 @@ class TimelineUserStoryConfiguration {
required this.service, required this.service,
required this.optionsBuilder, required this.optionsBuilder,
this.userId = 'test_user', this.userId = 'test_user',
this.openPageBuilder, this.homeOpenPageBuilder,
this.postCreationOpenPageBuilder,
this.postViewOpenPageBuilder,
this.postOverviewOpenPageBuilder,
this.onPostTap, this.onPostTap,
this.onUserTap, this.onUserTap,
this.onPostDelete, this.onPostDelete,
@ -68,8 +71,44 @@ class TimelineUserStoryConfiguration {
/// A function that builds TimelineOptions based on the given BuildContext. /// A function that builds TimelineOptions based on the given BuildContext.
final TimelineOptions Function(BuildContext context) optionsBuilder; final TimelineOptions Function(BuildContext context) optionsBuilder;
/// A function that defines the behavior when a page needs to be opened. /// Open page builder function for the home page. This function accepts
final Function(BuildContext context, Widget child)? openPageBuilder; /// 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. /// A callback function invoked when a timeline post is tapped.
final Function(BuildContext context, TimelinePost post)? onPostTap; final Function(BuildContext context, TimelinePost post)? onPostTap;

View file

@ -3,7 +3,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
name: flutter_timeline name: flutter_timeline
description: Visual elements and interface combined into one package description: Visual elements and interface combined into one package
version: 2.2.0 version: 2.3.0
publish_to: none publish_to: none
@ -19,13 +19,13 @@ dependencies:
git: git:
url: https://github.com/Iconica-Development/flutter_timeline url: https://github.com/Iconica-Development/flutter_timeline
path: packages/flutter_timeline_view path: packages/flutter_timeline_view
ref: 2.2.0 ref: 2.3.0
flutter_timeline_interface: flutter_timeline_interface:
git: git:
url: https://github.com/Iconica-Development/flutter_timeline url: https://github.com/Iconica-Development/flutter_timeline
path: packages/flutter_timeline_interface path: packages/flutter_timeline_interface
ref: 2.2.0 ref: 2.3.0
dev_dependencies: dev_dependencies:
flutter_lints: ^2.0.0 flutter_lints: ^2.0.0

View file

@ -4,7 +4,7 @@
name: flutter_timeline_firebase name: flutter_timeline_firebase
description: Implementation of the Flutter Timeline interface for Firebase. description: Implementation of the Flutter Timeline interface for Firebase.
version: 2.2.0 version: 2.3.0
publish_to: none publish_to: none
@ -23,7 +23,7 @@ dependencies:
git: git:
url: https://github.com/Iconica-Development/flutter_timeline url: https://github.com/Iconica-Development/flutter_timeline
path: packages/flutter_timeline_interface path: packages/flutter_timeline_interface
ref: 2.2.0 ref: 2.3.0
dev_dependencies: dev_dependencies:
flutter_lints: ^2.0.0 flutter_lints: ^2.0.0

View file

@ -4,7 +4,7 @@
name: flutter_timeline_interface name: flutter_timeline_interface
description: Interface for the service of the Flutter Timeline component description: Interface for the service of the Flutter Timeline component
version: 2.2.0 version: 2.3.0
publish_to: none publish_to: none

View file

@ -30,9 +30,7 @@ class TimelinePostOverviewScreen extends StatelessWidget {
userId: timelinePost.creatorId, userId: timelinePost.creatorId,
options: options, options: options,
post: timelinePost, post: timelinePost,
onPostDelete: () async { onPostDelete: () async {},
await service.postService.deletePost(timelinePost);
},
service: service, service: service,
), ),
), ),

View file

@ -4,7 +4,7 @@
name: flutter_timeline_view name: flutter_timeline_view
description: Visual elements of the Flutter Timeline Component description: Visual elements of the Flutter Timeline Component
version: 2.2.0 version: 2.3.0
publish_to: none publish_to: none
@ -23,7 +23,7 @@ dependencies:
git: git:
url: https://github.com/Iconica-Development/flutter_timeline url: https://github.com/Iconica-Development/flutter_timeline
path: packages/flutter_timeline_interface path: packages/flutter_timeline_interface
ref: 2.2.0 ref: 2.3.0
flutter_image_picker: flutter_image_picker:
git: git:
url: https://github.com/Iconica-Development/flutter_image_picker url: https://github.com/Iconica-Development/flutter_image_picker