From 2225a2a2c2207a4b165ff6f815f0c1f28bfeac42 Mon Sep 17 00:00:00 2001 From: FahadFahim71 <45163265+FahadFahim71@users.noreply.github.com> Date: Wed, 21 Feb 2024 15:37:05 +0100 Subject: [PATCH] feat(post-creation): add post overview screen before posting --- CHANGELOG.md | 4 +- .../example/lib/apps/navigator/app.dart | 8 ++- .../example/lib/apps/widgets/app.dart | 7 ++- .../example/lib/config/config.dart | 46 +++++++++++++--- .../src/models/timeline_configuration.dart | 4 ++ packages/flutter_timeline/pubspec.yaml | 6 +-- .../flutter_timeline_firebase/pubspec.yaml | 4 +- .../flutter_timeline_interface/pubspec.yaml | 2 +- .../lib/flutter_timeline_view.dart | 1 + .../lib/src/config/timeline_translations.dart | 13 ++++- .../timeline_post_creation_screen.dart | 14 ++++- .../timeline_post_overview_screen.dart | 52 +++++++++++++++++++ packages/flutter_timeline_view/pubspec.yaml | 4 +- 13 files changed, 144 insertions(+), 21 deletions(-) create mode 100644 packages/flutter_timeline_view/lib/src/screens/timeline_post_overview_screen.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index b0fdcc1..745d2f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ -## 2.0.1 +## 2.1.0 - Fixed multiline textfield not being dismissible. - Fixed liking a new post you created. +- Added options to require image and enforce content length in post creation +- Added post overview screen before creating post ## 1.0.0 - November 27 2023 diff --git a/packages/flutter_timeline/example/lib/apps/navigator/app.dart b/packages/flutter_timeline/example/lib/apps/navigator/app.dart index 434d595..0cbed13 100644 --- a/packages/flutter_timeline/example/lib/apps/navigator/app.dart +++ b/packages/flutter_timeline/example/lib/apps/navigator/app.dart @@ -43,8 +43,12 @@ class _MyHomePageState extends State { children: [ FloatingActionButton( heroTag: 'btn1', - onPressed: () => - createPost(context, timelineService, timelineOptions), + onPressed: () => createPost( + context, + timelineService, + timelineOptions, + getConfig(timelineService), + ), child: const Icon( Icons.edit, color: Colors.white, diff --git a/packages/flutter_timeline/example/lib/apps/widgets/app.dart b/packages/flutter_timeline/example/lib/apps/widgets/app.dart index 2292e17..95b1252 100644 --- a/packages/flutter_timeline/example/lib/apps/widgets/app.dart +++ b/packages/flutter_timeline/example/lib/apps/widgets/app.dart @@ -45,7 +45,12 @@ class _MyHomePageState extends State { FloatingActionButton( heroTag: 'btn1', onPressed: () { - createPost(context, timelineService, timelineOptions); + createPost( + context, + timelineService, + timelineOptions, + getConfig(timelineService), + ); }, child: const Icon( Icons.edit, diff --git a/packages/flutter_timeline/example/lib/config/config.dart b/packages/flutter_timeline/example/lib/config/config.dart index 0728bdf..9b54ccc 100644 --- a/packages/flutter_timeline/example/lib/config/config.dart +++ b/packages/flutter_timeline/example/lib/config/config.dart @@ -3,9 +3,10 @@ import 'package:flutter_timeline/flutter_timeline.dart'; TimelineUserStoryConfiguration getConfig(TimelineService service) { return TimelineUserStoryConfiguration( - service: service, - userId: 'test_user', - optionsBuilder: (context) => options); + service: service, + userId: 'test_user', + optionsBuilder: (context) => options, + ); } var options = TimelineOptions( @@ -33,9 +34,39 @@ var options = TimelineOptions( ), ); -void createPost(BuildContext context, TimelineService service, - TimelineOptions options) async { - await Navigator.push( +void navigateToOverview( + BuildContext context, + TimelineService service, + TimelineOptions options, + TimelinePost post, +) { + if (context.mounted) { + Navigator.of(context).pop(); + } + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => TimelinePostOverviewScreen( + timelinePost: post, + options: options, + service: service, + onPostSubmit: (post) { + service.postService.createPost(post); + if (context.mounted) { + Navigator.of(context).pop(); + } + }, + ), + ), + ); +} + +void createPost( + BuildContext context, + TimelineService service, + TimelineOptions options, + TimelineUserStoryConfiguration configuration) async { + await Navigator.pushReplacement( context, MaterialPageRoute( builder: (context) => Scaffold( @@ -47,6 +78,9 @@ void createPost(BuildContext context, TimelineService service, onPostCreated: (post) { Navigator.of(context).pop(); }, + onPostOverview: (post) { + navigateToOverview(context, service, options, post); + }, ), ), ), diff --git a/packages/flutter_timeline/lib/src/models/timeline_configuration.dart b/packages/flutter_timeline/lib/src/models/timeline_configuration.dart index b83e566..fc14ee6 100644 --- a/packages/flutter_timeline/lib/src/models/timeline_configuration.dart +++ b/packages/flutter_timeline/lib/src/models/timeline_configuration.dart @@ -55,6 +55,7 @@ class TimelineUserStoryConfiguration { this.onPostDelete, this.filterEnabled = false, this.postWidgetBuilder, + this.enablePostOverviewScreen = false, }); /// The ID of the user associated with this user story configuration. @@ -84,4 +85,7 @@ class TimelineUserStoryConfiguration { /// A function that builds a widget for a timeline post. final Widget Function(TimelinePost post)? postWidgetBuilder; + + /// Boolean to enable timeline post overview screen before submitting + final bool enablePostOverviewScreen; } diff --git a/packages/flutter_timeline/pubspec.yaml b/packages/flutter_timeline/pubspec.yaml index 83e93f5..d756f7b 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.0.0 +version: 2.1.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.0.0 + ref: 2.1.0 flutter_timeline_interface: git: url: https://github.com/Iconica-Development/flutter_timeline path: packages/flutter_timeline_interface - ref: 2.0.0 + ref: 2.1.0 dev_dependencies: flutter_lints: ^2.0.0 diff --git a/packages/flutter_timeline_firebase/pubspec.yaml b/packages/flutter_timeline_firebase/pubspec.yaml index cefbac5..801453b 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.0.0 +version: 2.1.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.0.0 + ref: 2.1.0 dev_dependencies: flutter_lints: ^2.0.0 diff --git a/packages/flutter_timeline_interface/pubspec.yaml b/packages/flutter_timeline_interface/pubspec.yaml index 0530663..5c1ceb3 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.0.0 +version: 2.1.0 publish_to: none diff --git a/packages/flutter_timeline_view/lib/flutter_timeline_view.dart b/packages/flutter_timeline_view/lib/flutter_timeline_view.dart index 1ef76bd..1a63bf4 100644 --- a/packages/flutter_timeline_view/lib/flutter_timeline_view.dart +++ b/packages/flutter_timeline_view/lib/flutter_timeline_view.dart @@ -9,6 +9,7 @@ export 'src/config/timeline_styles.dart'; export 'src/config/timeline_theme.dart'; export 'src/config/timeline_translations.dart'; export 'src/screens/timeline_post_creation_screen.dart'; +export 'src/screens/timeline_post_overview_screen.dart'; export 'src/screens/timeline_post_screen.dart'; export 'src/screens/timeline_screen.dart'; export 'src/screens/timeline_selection_screen.dart'; diff --git a/packages/flutter_timeline_view/lib/src/config/timeline_translations.dart b/packages/flutter_timeline_view/lib/src/config/timeline_translations.dart index f43a3a4..df04d83 100644 --- a/packages/flutter_timeline_view/lib/src/config/timeline_translations.dart +++ b/packages/flutter_timeline_view/lib/src/config/timeline_translations.dart @@ -29,6 +29,8 @@ class TimelineTranslations { required this.postLoadingError, required this.timelineSelectionDescription, required this.searchHint, + required this.postOverview, + required this.postIn, }); const TimelineTranslations.empty() @@ -54,7 +56,9 @@ class TimelineTranslations { postAt = 'at', postLoadingError = 'Something went wrong while loading the post', timelineSelectionDescription = 'Choose a category', - searchHint = 'Search...'; + searchHint = 'Search...', + postOverview = 'Post Overview', + postIn = 'Post in'; final String noPosts; final String noPostsWithFilter; @@ -83,6 +87,9 @@ class TimelineTranslations { final String searchHint; + final String postOverview; + final String postIn; + TimelineTranslations copyWith({ String? noPosts, String? noPostsWithFilter, @@ -106,6 +113,8 @@ class TimelineTranslations { String? postLoadingError, String? timelineSelectionDescription, String? searchHint, + String? postOverview, + String? postIn, }) => TimelineTranslations( noPosts: noPosts ?? this.noPosts, @@ -133,5 +142,7 @@ class TimelineTranslations { timelineSelectionDescription: timelineSelectionDescription ?? this.timelineSelectionDescription, searchHint: searchHint ?? this.searchHint, + postOverview: postOverview ?? this.postOverview, + postIn: postIn ?? this.postIn, ); } diff --git a/packages/flutter_timeline_view/lib/src/screens/timeline_post_creation_screen.dart b/packages/flutter_timeline_view/lib/src/screens/timeline_post_creation_screen.dart index 8358d6d..6d82ff0 100644 --- a/packages/flutter_timeline_view/lib/src/screens/timeline_post_creation_screen.dart +++ b/packages/flutter_timeline_view/lib/src/screens/timeline_post_creation_screen.dart @@ -8,6 +8,7 @@ import 'package:dotted_border/dotted_border.dart'; import 'package:flutter/material.dart'; import 'package:flutter_image_picker/flutter_image_picker.dart'; import 'package:flutter_timeline_interface/flutter_timeline_interface.dart'; +import 'package:flutter_timeline_view/flutter_timeline_view.dart'; import 'package:flutter_timeline_view/src/config/timeline_options.dart'; class TimelinePostCreationScreen extends StatefulWidget { @@ -17,6 +18,7 @@ class TimelinePostCreationScreen extends StatefulWidget { required this.service, required this.options, this.postCategory, + this.onPostOverview, super.key, }); @@ -33,6 +35,9 @@ class TimelinePostCreationScreen extends StatefulWidget { /// The options for the timeline final TimelineOptions options; + /// Nullable callback for routing to the post overview + final void Function(TimelinePost)? onPostOverview; + @override State createState() => _TimelinePostCreationScreenState(); @@ -101,8 +106,13 @@ class _TimelinePostCreationScreenState reactionEnabled: allowComments, image: image, ); - var newPost = await widget.service.postService.createPost(post); - widget.onPostCreated.call(newPost); + + if (widget.onPostOverview != null) { + widget.onPostOverview?.call(post); + } else { + var newPost = await widget.service.postService.createPost(post); + widget.onPostCreated.call(newPost); + } } var theme = Theme.of(context); 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 new file mode 100644 index 0000000..b36cb2e --- /dev/null +++ b/packages/flutter_timeline_view/lib/src/screens/timeline_post_overview_screen.dart @@ -0,0 +1,52 @@ +// ignore_for_file: prefer_expression_function_bodies + +import 'package:flutter/material.dart'; +import 'package:flutter_timeline_interface/flutter_timeline_interface.dart'; +import 'package:flutter_timeline_view/flutter_timeline_view.dart'; + +class TimelinePostOverviewScreen extends StatelessWidget { + const TimelinePostOverviewScreen({ + required this.timelinePost, + required this.options, + required this.service, + required this.onPostSubmit, + super.key, + }); + final TimelinePost timelinePost; + final TimelineOptions options; + final TimelineService service; + final void Function(TimelinePost) onPostSubmit; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text(options.translations.postOverview), + ), + body: Column( + children: [ + Flexible( + child: TimelinePostScreen( + userId: timelinePost.creatorId, + options: options, + post: timelinePost, + onPostDelete: () {}, + service: service, + ), + ), + Padding( + padding: const EdgeInsets.only(bottom: 30.0), + child: ElevatedButton( + onPressed: () { + onPostSubmit(timelinePost); + }, + child: Text( + '${options.translations.postIn} ${timelinePost.category}', + ), + ), + ), + ], + ), + ); + } +} diff --git a/packages/flutter_timeline_view/pubspec.yaml b/packages/flutter_timeline_view/pubspec.yaml index 3b1cbce..98de79b 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.0.0 +version: 2.1.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.0.0 + ref: 2.1.0 flutter_image_picker: git: url: https://github.com/Iconica-Development/flutter_image_picker