fix: show category title everywhere and use category key for storing posts

This commit is contained in:
Freek van de Ven 2024-05-23 11:12:22 +02:00
parent 767215a53e
commit 25264ba44b
5 changed files with 43 additions and 34 deletions

View file

@ -14,6 +14,7 @@
- Add a TimelinePaddingOptions class to store the padding options for the timeline - Add a TimelinePaddingOptions class to store the padding options for the timeline
- fix the avatar size to match the new design - fix the avatar size to match the new design
- Add the iconbutton for image uploading back to the ReactionBottom - 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 ## 3.0.1

View file

@ -96,10 +96,12 @@ List<GoRoute> getTimelineStoryRoutes({
categories: config categories: config
.optionsBuilder(context) .optionsBuilder(context)
.categoriesOptions .categoriesOptions
.categoriesBuilder!(context), .categoriesBuilder
?.call(context) ??
[],
onCategorySelected: (category) async { onCategorySelected: (category) async {
await context.push( await context.push(
TimelineUserStoryRoutes.timelinepostCreation(category.title), TimelineUserStoryRoutes.timelinepostCreation(category.key ?? ''),
); );
}, },
); );
@ -177,7 +179,7 @@ List<GoRoute> getTimelineStoryRoutes({
leading: backButton, leading: backButton,
backgroundColor: const Color(0xff212121), backgroundColor: const Color(0xff212121),
title: Text( title: Text(
post.category ?? 'Category', category?.title ?? post.category ?? 'Category',
style: TextStyle( style: TextStyle(
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
fontSize: 24, fontSize: 24,

View file

@ -156,7 +156,7 @@ Widget _postDetailScreenRoute({
leading: backButton, leading: backButton,
backgroundColor: const Color(0xff212121), backgroundColor: const Color(0xff212121),
title: Text( title: Text(
post.category ?? 'Category', category?.title ?? post.category ?? 'Category',
style: TextStyle( style: TextStyle(
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
fontSize: 24, fontSize: 24,
@ -193,7 +193,7 @@ Widget _postCreationScreenRoute({
service: config.service, service: config.service,
onPostCreated: (post) async { onPostCreated: (post) async {
var newPost = await config.service.postService.createPost(post); var newPost = await config.service.postService.createPost(post);
if (context.mounted) { if (!context.mounted) return;
if (config.afterPostCreationGoHome) { if (config.afterPostCreationGoHome) {
await Navigator.pushReplacement( await Navigator.pushReplacement(
context, context,
@ -216,7 +216,6 @@ Widget _postCreationScreenRoute({
), ),
); );
} }
}
}, },
onPostOverview: (post) async => Navigator.of(context).push( onPostOverview: (post) async => Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
@ -228,7 +227,7 @@ Widget _postCreationScreenRoute({
), ),
), ),
enablePostOverviewScreen: config.enablePostOverviewScreen, enablePostOverviewScreen: config.enablePostOverviewScreen,
postCategory: category.title, postCategory: category.key,
); );
var backButton = IconButton( var backButton = IconButton(
@ -343,7 +342,9 @@ Widget _postCategorySelectionScreen({
categories: config categories: config
.optionsBuilder(context) .optionsBuilder(context)
.categoriesOptions .categoriesOptions
.categoriesBuilder!(context), .categoriesBuilder
?.call(context) ??
[],
onCategorySelected: (category) async { onCategorySelected: (category) async {
await Navigator.of(context).push( await Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(

View file

@ -9,10 +9,8 @@ class FirebaseTimelineOptions {
const FirebaseTimelineOptions({ const FirebaseTimelineOptions({
this.usersCollectionName = 'users', this.usersCollectionName = 'users',
this.timelineCollectionName = 'timeline', this.timelineCollectionName = 'timeline',
this.allTimelineCategories = const [],
}); });
final String usersCollectionName; final String usersCollectionName;
final String timelineCollectionName; final String timelineCollectionName;
final List<String> allTimelineCategories;
} }

View file

@ -1,5 +1,6 @@
// ignore_for_file: prefer_expression_function_bodies // ignore_for_file: prefer_expression_function_bodies
import 'package:collection/collection.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_timeline_interface/flutter_timeline_interface.dart'; import 'package:flutter_timeline_interface/flutter_timeline_interface.dart';
import 'package:flutter_timeline_view/flutter_timeline_view.dart'; import 'package:flutter_timeline_view/flutter_timeline_view.dart';
@ -19,7 +20,13 @@ class TimelinePostOverviewScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { 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( return Column(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ children: [