From 25264ba44b54082a99eea054204b683291310eb0 Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Thu, 23 May 2024 11:12:22 +0200 Subject: [PATCH] fix: show category title everywhere and use category key for storing posts --- CHANGELOG.md | 1 + .../flutter_timeline_gorouter_userstory.dart | 12 +++-- .../flutter_timeline_navigator_userstory.dart | 53 ++++++++++--------- .../src/config/firebase_timeline_options.dart | 2 - .../timeline_post_overview_screen.dart | 9 +++- 5 files changed, 43 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81de943..4a58fd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Add a TimelinePaddingOptions class to store the padding options for the timeline - fix the avatar size to match the new design - Add the iconbutton for image uploading back to the ReactionBottom +- Fix category key is correctly used for saving timeline posts and category title is shown everywhere ## 3.0.1 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 8026163..5a34d81 100644 --- a/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart +++ b/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart @@ -94,12 +94,14 @@ List getTimelineStoryRoutes({ var timelineSelectionScreen = TimelineSelectionScreen( options: config.optionsBuilder(context), categories: config - .optionsBuilder(context) - .categoriesOptions - .categoriesBuilder!(context), + .optionsBuilder(context) + .categoriesOptions + .categoriesBuilder + ?.call(context) ?? + [], onCategorySelected: (category) async { await context.push( - TimelineUserStoryRoutes.timelinepostCreation(category.title), + TimelineUserStoryRoutes.timelinepostCreation(category.key ?? ''), ); }, ); @@ -177,7 +179,7 @@ List getTimelineStoryRoutes({ leading: backButton, backgroundColor: const Color(0xff212121), title: Text( - post.category ?? 'Category', + category?.title ?? post.category ?? 'Category', style: TextStyle( color: Theme.of(context).primaryColor, fontSize: 24, 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 48288e6..e25b67c 100644 --- a/packages/flutter_timeline/lib/src/flutter_timeline_navigator_userstory.dart +++ b/packages/flutter_timeline/lib/src/flutter_timeline_navigator_userstory.dart @@ -156,7 +156,7 @@ Widget _postDetailScreenRoute({ leading: backButton, backgroundColor: const Color(0xff212121), title: Text( - post.category ?? 'Category', + category?.title ?? post.category ?? 'Category', style: TextStyle( color: Theme.of(context).primaryColor, fontSize: 24, @@ -193,29 +193,28 @@ Widget _postCreationScreenRoute({ service: config.service, onPostCreated: (post) async { var newPost = await config.service.postService.createPost(post); - if (context.mounted) { - if (config.afterPostCreationGoHome) { - await Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (context) => _timelineScreenRoute( - configuration: config, - context: context, - ), + if (!context.mounted) return; + if (config.afterPostCreationGoHome) { + await Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (context) => _timelineScreenRoute( + configuration: config, + context: context, ), - ); - } else { - await Navigator.push( - context, - MaterialPageRoute( - builder: (context) => _postOverviewScreenRoute( - configuration: config, - context: context, - post: newPost, - ), + ), + ); + } else { + await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => _postOverviewScreenRoute( + configuration: config, + context: context, + post: newPost, ), - ); - } + ), + ); } }, onPostOverview: (post) async => Navigator.of(context).push( @@ -228,7 +227,7 @@ Widget _postCreationScreenRoute({ ), ), enablePostOverviewScreen: config.enablePostOverviewScreen, - postCategory: category.title, + postCategory: category.key, ); var backButton = IconButton( @@ -341,9 +340,11 @@ Widget _postCategorySelectionScreen({ var timelineSelectionScreen = TimelineSelectionScreen( options: config.optionsBuilder(context), categories: config - .optionsBuilder(context) - .categoriesOptions - .categoriesBuilder!(context), + .optionsBuilder(context) + .categoriesOptions + .categoriesBuilder + ?.call(context) ?? + [], onCategorySelected: (category) async { await Navigator.of(context).push( MaterialPageRoute( diff --git a/packages/flutter_timeline_firebase/lib/src/config/firebase_timeline_options.dart b/packages/flutter_timeline_firebase/lib/src/config/firebase_timeline_options.dart index 6acd32a..0c83cb9 100644 --- a/packages/flutter_timeline_firebase/lib/src/config/firebase_timeline_options.dart +++ b/packages/flutter_timeline_firebase/lib/src/config/firebase_timeline_options.dart @@ -9,10 +9,8 @@ class FirebaseTimelineOptions { const FirebaseTimelineOptions({ this.usersCollectionName = 'users', this.timelineCollectionName = 'timeline', - this.allTimelineCategories = const [], }); final String usersCollectionName; final String timelineCollectionName; - final List allTimelineCategories; } 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 e810fe1..6293dfc 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 @@ -1,5 +1,6 @@ // ignore_for_file: prefer_expression_function_bodies +import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:flutter_timeline_interface/flutter_timeline_interface.dart'; import 'package:flutter_timeline_view/flutter_timeline_view.dart'; @@ -19,7 +20,13 @@ class TimelinePostOverviewScreen extends StatelessWidget { @override Widget build(BuildContext context) { - var buttonText = '${options.translations.postIn} ${timelinePost.category}'; + // the timelinePost.category is a key so we need to get the category object + var timelineCategoryName = options.categoriesOptions.categoriesBuilder + ?.call(context) + .firstWhereOrNull((element) => element.key == timelinePost.category) + ?.title ?? + timelinePost.category; + var buttonText = '${options.translations.postIn} $timelineCategoryName'; return Column( mainAxisSize: MainAxisSize.max, children: [