mirror of
https://github.com/Iconica-Development/flutter_timeline.git
synced 2025-05-18 18:13:46 +02:00
fix: postModel not including creator
This commit is contained in:
parent
49f0853cca
commit
8188c179fb
6 changed files with 144 additions and 150 deletions
|
@ -23,7 +23,7 @@ Widget timeLineNavigatorUserStory({
|
|||
optionsBuilder: (context) => const TimelineOptions(),
|
||||
);
|
||||
|
||||
return _timelineScreenRoute(configuration: config, context: context);
|
||||
return _timelineScreenRoute(config: config, context: context);
|
||||
}
|
||||
|
||||
/// A widget function that creates a timeline screen route.
|
||||
|
@ -33,18 +33,11 @@ Widget timeLineNavigatorUserStory({
|
|||
/// parameters. If no configuration is provided, default values will be used.
|
||||
Widget _timelineScreenRoute({
|
||||
required BuildContext context,
|
||||
TimelineUserStoryConfiguration? configuration,
|
||||
required TimelineUserStoryConfiguration config,
|
||||
String? initalCategory,
|
||||
}) {
|
||||
var config = configuration ??
|
||||
TimelineUserStoryConfiguration(
|
||||
userId: 'test_user',
|
||||
service: TimelineService(
|
||||
postService: LocalTimelinePostService(),
|
||||
),
|
||||
optionsBuilder: (context) => const TimelineOptions(),
|
||||
);
|
||||
|
||||
var timelineScreen = TimelineScreen(
|
||||
timelineCategory: initalCategory,
|
||||
userId: config.getUserId?.call(context) ?? config.userId,
|
||||
allowAllDeletion: config.canDeleteAllPosts?.call(context) ?? false,
|
||||
onUserTap: (user) => config.onUserTap?.call(context, user),
|
||||
|
@ -55,7 +48,7 @@ Widget _timelineScreenRoute({
|
|||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => _postDetailScreenRoute(
|
||||
configuration: config,
|
||||
config: config,
|
||||
context: context,
|
||||
post: post,
|
||||
),
|
||||
|
@ -78,7 +71,7 @@ Widget _timelineScreenRoute({
|
|||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => _postCreationScreenRoute(
|
||||
configuration: config,
|
||||
config: config,
|
||||
context: context,
|
||||
category: selectedCategory,
|
||||
),
|
||||
|
@ -88,7 +81,7 @@ Widget _timelineScreenRoute({
|
|||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => _postCategorySelectionScreen(
|
||||
configuration: config,
|
||||
config: config,
|
||||
context: context,
|
||||
),
|
||||
),
|
||||
|
@ -125,17 +118,8 @@ Widget _timelineScreenRoute({
|
|||
Widget _postDetailScreenRoute({
|
||||
required BuildContext context,
|
||||
required TimelinePost post,
|
||||
TimelineUserStoryConfiguration? configuration,
|
||||
required TimelineUserStoryConfiguration config,
|
||||
}) {
|
||||
var config = configuration ??
|
||||
TimelineUserStoryConfiguration(
|
||||
userId: 'test_user',
|
||||
service: TimelineService(
|
||||
postService: LocalTimelinePostService(),
|
||||
),
|
||||
optionsBuilder: (context) => const TimelineOptions(),
|
||||
);
|
||||
|
||||
var timelinePostScreen = TimelinePostScreen(
|
||||
userId: config.getUserId?.call(context) ?? config.userId,
|
||||
allowAllDeletion: config.canDeleteAllPosts?.call(context) ?? false,
|
||||
|
@ -166,7 +150,7 @@ Widget _postDetailScreenRoute({
|
|||
?.call(context, timelinePostScreen, backButton, post, category) ??
|
||||
Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: backButton,
|
||||
iconTheme: Theme.of(context).appBarTheme.iconTheme,
|
||||
title: Text(
|
||||
category.title.toLowerCase(),
|
||||
style: TextStyle(
|
||||
|
@ -188,31 +172,24 @@ Widget _postDetailScreenRoute({
|
|||
Widget _postCreationScreenRoute({
|
||||
required BuildContext context,
|
||||
required TimelineCategory category,
|
||||
TimelineUserStoryConfiguration? configuration,
|
||||
required TimelineUserStoryConfiguration config,
|
||||
}) {
|
||||
var config = configuration ??
|
||||
TimelineUserStoryConfiguration(
|
||||
userId: 'test_user',
|
||||
service: TimelineService(
|
||||
postService: LocalTimelinePostService(),
|
||||
),
|
||||
optionsBuilder: (context) => const TimelineOptions(),
|
||||
);
|
||||
|
||||
var timelinePostCreationScreen = TimelinePostCreationScreen(
|
||||
userId: config.getUserId?.call(context) ?? config.userId,
|
||||
options: config.optionsBuilder(context),
|
||||
service: config.service,
|
||||
onPostCreated: (post) async {
|
||||
var newPost = await config.service.postService.createPost(post);
|
||||
|
||||
if (!context.mounted) return;
|
||||
if (config.afterPostCreationGoHome) {
|
||||
await Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => _timelineScreenRoute(
|
||||
configuration: config,
|
||||
config: config,
|
||||
context: context,
|
||||
initalCategory: category.title,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -221,7 +198,7 @@ Widget _postCreationScreenRoute({
|
|||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => _postOverviewScreenRoute(
|
||||
configuration: config,
|
||||
config: config,
|
||||
context: context,
|
||||
post: newPost,
|
||||
),
|
||||
|
@ -232,7 +209,7 @@ Widget _postCreationScreenRoute({
|
|||
onPostOverview: (post) async => Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => _postOverviewScreenRoute(
|
||||
configuration: config,
|
||||
config: config,
|
||||
context: context,
|
||||
post: post,
|
||||
),
|
||||
|
@ -254,6 +231,7 @@ Widget _postCreationScreenRoute({
|
|||
?.call(context, timelinePostCreationScreen, backButton) ??
|
||||
Scaffold(
|
||||
appBar: AppBar(
|
||||
iconTheme: Theme.of(context).appBarTheme.iconTheme,
|
||||
leading: backButton,
|
||||
title: Text(
|
||||
config.optionsBuilder(context).translations.postCreation,
|
||||
|
@ -277,17 +255,8 @@ Widget _postCreationScreenRoute({
|
|||
Widget _postOverviewScreenRoute({
|
||||
required BuildContext context,
|
||||
required TimelinePost post,
|
||||
TimelineUserStoryConfiguration? configuration,
|
||||
required TimelineUserStoryConfiguration config,
|
||||
}) {
|
||||
var config = configuration ??
|
||||
TimelineUserStoryConfiguration(
|
||||
userId: 'test_user',
|
||||
service: TimelineService(
|
||||
postService: LocalTimelinePostService(),
|
||||
),
|
||||
optionsBuilder: (context) => const TimelineOptions(),
|
||||
);
|
||||
|
||||
var timelinePostOverviewWidget = TimelinePostOverviewScreen(
|
||||
options: config.optionsBuilder(context),
|
||||
service: config.service,
|
||||
|
@ -297,8 +266,11 @@ Widget _postOverviewScreenRoute({
|
|||
if (context.mounted) {
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
_timelineScreenRoute(configuration: config, context: context),
|
||||
builder: (context) => _timelineScreenRoute(
|
||||
config: config,
|
||||
context: context,
|
||||
initalCategory: post.category,
|
||||
),
|
||||
),
|
||||
(route) => false,
|
||||
);
|
||||
|
@ -320,6 +292,7 @@ Widget _postOverviewScreenRoute({
|
|||
) ??
|
||||
Scaffold(
|
||||
appBar: AppBar(
|
||||
iconTheme: Theme.of(context).appBarTheme.iconTheme,
|
||||
leading: backButton,
|
||||
title: Text(
|
||||
config.optionsBuilder(context).translations.postCreation,
|
||||
|
@ -336,17 +309,8 @@ Widget _postOverviewScreenRoute({
|
|||
|
||||
Widget _postCategorySelectionScreen({
|
||||
required BuildContext context,
|
||||
TimelineUserStoryConfiguration? configuration,
|
||||
required TimelineUserStoryConfiguration config,
|
||||
}) {
|
||||
var config = configuration ??
|
||||
TimelineUserStoryConfiguration(
|
||||
userId: 'test_user',
|
||||
service: TimelineService(
|
||||
postService: LocalTimelinePostService(),
|
||||
),
|
||||
optionsBuilder: (context) => const TimelineOptions(),
|
||||
);
|
||||
|
||||
var timelineSelectionScreen = TimelineSelectionScreen(
|
||||
postService: config.service.postService,
|
||||
options: config.optionsBuilder(context),
|
||||
|
@ -355,7 +319,7 @@ Widget _postCategorySelectionScreen({
|
|||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => _postCreationScreenRoute(
|
||||
configuration: config,
|
||||
config: config,
|
||||
context: context,
|
||||
category: category,
|
||||
),
|
||||
|
@ -376,6 +340,7 @@ Widget _postCategorySelectionScreen({
|
|||
?.call(context, timelineSelectionScreen) ??
|
||||
Scaffold(
|
||||
appBar: AppBar(
|
||||
iconTheme: Theme.of(context).appBarTheme.iconTheme,
|
||||
leading: backButton,
|
||||
title: Text(
|
||||
config.optionsBuilder(context).translations.postCreation,
|
||||
|
|
|
@ -13,11 +13,28 @@ class TimelinePosterUserModel {
|
|||
this.imageUrl,
|
||||
});
|
||||
|
||||
factory TimelinePosterUserModel.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
String userId,
|
||||
) =>
|
||||
TimelinePosterUserModel(
|
||||
userId: userId,
|
||||
firstName: json['first_name'] as String?,
|
||||
lastName: json['last_name'] as String?,
|
||||
imageUrl: json['image_url'] as String?,
|
||||
);
|
||||
|
||||
final String userId;
|
||||
final String? firstName;
|
||||
final String? lastName;
|
||||
final String? imageUrl;
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'first_name': firstName,
|
||||
'last_name': lastName,
|
||||
'image_url': imageUrl,
|
||||
};
|
||||
|
||||
String? get fullName {
|
||||
var fullName = '';
|
||||
|
||||
|
|
|
@ -160,6 +160,7 @@ class TimelineOptions {
|
|||
BuildContext context,
|
||||
Function() onPressed,
|
||||
String text,
|
||||
TimelinePost post,
|
||||
)? postOverviewButtonBuilder;
|
||||
|
||||
/// Optional builder to override the default alertdialog for post deletion
|
||||
|
|
|
@ -61,6 +61,7 @@ class _TimelinePostCreationScreenState
|
|||
void initState() {
|
||||
titleController.addListener(_listenForInputs);
|
||||
contentController.addListener(_listenForInputs);
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
@ -77,6 +78,7 @@ class _TimelinePostCreationScreenState
|
|||
var imageRequired = widget.options.requireImageForPost;
|
||||
|
||||
Future<void> onPostCreated() async {
|
||||
var user = await widget.service.userService?.getUser(widget.userId);
|
||||
var post = TimelinePost(
|
||||
id: 'Post${Random().nextInt(1000)}',
|
||||
creatorId: widget.userId,
|
||||
|
@ -89,6 +91,7 @@ class _TimelinePostCreationScreenState
|
|||
createdAt: DateTime.now(),
|
||||
reactionEnabled: allowComments,
|
||||
image: image,
|
||||
creator: user,
|
||||
);
|
||||
|
||||
if (widget.enablePostOverviewScreen) {
|
||||
|
@ -362,7 +365,7 @@ class _TimelinePostCreationScreenState
|
|||
child: DefaultFilledButton(
|
||||
onPressed: titleIsValid &&
|
||||
contentIsValid &&
|
||||
(imageRequired ? image != null : true)
|
||||
(!imageRequired || image != null)
|
||||
? () async {
|
||||
if (formkey.currentState!
|
||||
.validate()) {
|
||||
|
|
|
@ -35,13 +35,18 @@ class TimelinePostOverviewScreen extends StatelessWidget {
|
|||
options.postOverviewButtonBuilder?.call(
|
||||
context,
|
||||
() {
|
||||
if (isSubmitted) return;
|
||||
isSubmitted = true;
|
||||
onPostSubmit(timelinePost);
|
||||
},
|
||||
options.translations.postIn,
|
||||
timelinePost,
|
||||
) ??
|
||||
options.buttonBuilder?.call(
|
||||
context,
|
||||
() {
|
||||
if (isSubmitted) return;
|
||||
isSubmitted = true;
|
||||
onPostSubmit(timelinePost);
|
||||
},
|
||||
options.translations.postIn,
|
||||
|
|
|
@ -36,105 +36,108 @@ class _TimelineSelectionScreenState extends State<TimelineSelectionScreen> {
|
|||
padding: EdgeInsets.symmetric(
|
||||
horizontal: size.width * 0.05,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 20, bottom: 12),
|
||||
child: Text(
|
||||
widget.options.translations.timelineSelectionDescription,
|
||||
style: theme.textTheme.titleLarge,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 20, bottom: 12),
|
||||
child: Text(
|
||||
widget.options.translations.timelineSelectionDescription,
|
||||
style: theme.textTheme.titleLarge,
|
||||
),
|
||||
),
|
||||
),
|
||||
for (var category in widget.categories.where(
|
||||
(element) => element.canCreate && element.key != null,
|
||||
)) ...[
|
||||
widget.options.categorySelectorButtonBuilder?.call(
|
||||
context,
|
||||
() {
|
||||
widget.onCategorySelected.call(category);
|
||||
},
|
||||
category.title,
|
||||
) ??
|
||||
InkWell(
|
||||
onTap: () => widget.onCategorySelected.call(category),
|
||||
child: Container(
|
||||
height: 60,
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: widget.options.theme
|
||||
.categorySelectionButtonBorderColor ??
|
||||
Theme.of(context).primaryColor,
|
||||
width: 2,
|
||||
),
|
||||
color: widget
|
||||
.options.theme.categorySelectionButtonBackgroundColor,
|
||||
),
|
||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||
child: Text(
|
||||
category.title,
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
for (var category in widget.categories.where(
|
||||
(element) => element.canCreate && element.key != null,
|
||||
)) ...[
|
||||
widget.options.categorySelectorButtonBuilder?.call(
|
||||
context,
|
||||
() {
|
||||
widget.onCategorySelected.call(category);
|
||||
},
|
||||
category.title,
|
||||
) ??
|
||||
InkWell(
|
||||
onTap: () => widget.onCategorySelected.call(category),
|
||||
child: Container(
|
||||
height: 60,
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: widget.options.theme
|
||||
.categorySelectionButtonBorderColor ??
|
||||
Theme.of(context).primaryColor,
|
||||
width: 2,
|
||||
),
|
||||
],
|
||||
color: widget.options.theme
|
||||
.categorySelectionButtonBackgroundColor,
|
||||
),
|
||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 12.0),
|
||||
child: Text(
|
||||
category.title,
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
InkWell(
|
||||
onTap: showCategoryPopup,
|
||||
child: Container(
|
||||
height: 60,
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: widget
|
||||
.options.theme.categorySelectionButtonBorderColor ??
|
||||
Theme.of(context).primaryColor,
|
||||
width: 2,
|
||||
),
|
||||
color: widget
|
||||
.options.theme.categorySelectionButtonBackgroundColor,
|
||||
),
|
||||
],
|
||||
InkWell(
|
||||
onTap: showCategoryPopup,
|
||||
child: Container(
|
||||
height: 60,
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color:
|
||||
widget.options.theme.categorySelectionButtonBorderColor ??
|
||||
Theme.of(context).primaryColor,
|
||||
width: 2,
|
||||
),
|
||||
color:
|
||||
widget.options.theme.categorySelectionButtonBackgroundColor,
|
||||
),
|
||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.add,
|
||||
color: theme.textTheme.titleMedium?.color!
|
||||
.withOpacity(0.5),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
widget.options.translations.addCategoryTitle,
|
||||
style: theme.textTheme.titleMedium!.copyWith(
|
||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.add,
|
||||
color: theme.textTheme.titleMedium?.color!
|
||||
.withOpacity(0.5),
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
widget.options.translations.addCategoryTitle,
|
||||
style: theme.textTheme.titleMedium!.copyWith(
|
||||
color: theme.textTheme.titleMedium?.color!
|
||||
.withOpacity(0.5),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue