mirror of
https://github.com/Iconica-Development/flutter_timeline.git
synced 2025-05-19 10:33:44 +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(),
|
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.
|
/// 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.
|
/// parameters. If no configuration is provided, default values will be used.
|
||||||
Widget _timelineScreenRoute({
|
Widget _timelineScreenRoute({
|
||||||
required BuildContext context,
|
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(
|
var timelineScreen = TimelineScreen(
|
||||||
|
timelineCategory: initalCategory,
|
||||||
userId: config.getUserId?.call(context) ?? config.userId,
|
userId: config.getUserId?.call(context) ?? config.userId,
|
||||||
allowAllDeletion: config.canDeleteAllPosts?.call(context) ?? false,
|
allowAllDeletion: config.canDeleteAllPosts?.call(context) ?? false,
|
||||||
onUserTap: (user) => config.onUserTap?.call(context, user),
|
onUserTap: (user) => config.onUserTap?.call(context, user),
|
||||||
|
@ -55,7 +48,7 @@ Widget _timelineScreenRoute({
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => _postDetailScreenRoute(
|
builder: (context) => _postDetailScreenRoute(
|
||||||
configuration: config,
|
config: config,
|
||||||
context: context,
|
context: context,
|
||||||
post: post,
|
post: post,
|
||||||
),
|
),
|
||||||
|
@ -78,7 +71,7 @@ Widget _timelineScreenRoute({
|
||||||
await Navigator.of(context).push(
|
await Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => _postCreationScreenRoute(
|
builder: (context) => _postCreationScreenRoute(
|
||||||
configuration: config,
|
config: config,
|
||||||
context: context,
|
context: context,
|
||||||
category: selectedCategory,
|
category: selectedCategory,
|
||||||
),
|
),
|
||||||
|
@ -88,7 +81,7 @@ Widget _timelineScreenRoute({
|
||||||
await Navigator.of(context).push(
|
await Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => _postCategorySelectionScreen(
|
builder: (context) => _postCategorySelectionScreen(
|
||||||
configuration: config,
|
config: config,
|
||||||
context: context,
|
context: context,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -125,17 +118,8 @@ Widget _timelineScreenRoute({
|
||||||
Widget _postDetailScreenRoute({
|
Widget _postDetailScreenRoute({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required TimelinePost post,
|
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(
|
var timelinePostScreen = TimelinePostScreen(
|
||||||
userId: config.getUserId?.call(context) ?? config.userId,
|
userId: config.getUserId?.call(context) ?? config.userId,
|
||||||
allowAllDeletion: config.canDeleteAllPosts?.call(context) ?? false,
|
allowAllDeletion: config.canDeleteAllPosts?.call(context) ?? false,
|
||||||
|
@ -166,7 +150,7 @@ Widget _postDetailScreenRoute({
|
||||||
?.call(context, timelinePostScreen, backButton, post, category) ??
|
?.call(context, timelinePostScreen, backButton, post, category) ??
|
||||||
Scaffold(
|
Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
leading: backButton,
|
iconTheme: Theme.of(context).appBarTheme.iconTheme,
|
||||||
title: Text(
|
title: Text(
|
||||||
category.title.toLowerCase(),
|
category.title.toLowerCase(),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
|
@ -188,31 +172,24 @@ Widget _postDetailScreenRoute({
|
||||||
Widget _postCreationScreenRoute({
|
Widget _postCreationScreenRoute({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required TimelineCategory category,
|
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(
|
var timelinePostCreationScreen = TimelinePostCreationScreen(
|
||||||
userId: config.getUserId?.call(context) ?? config.userId,
|
userId: config.getUserId?.call(context) ?? config.userId,
|
||||||
options: config.optionsBuilder(context),
|
options: config.optionsBuilder(context),
|
||||||
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) return;
|
if (!context.mounted) return;
|
||||||
if (config.afterPostCreationGoHome) {
|
if (config.afterPostCreationGoHome) {
|
||||||
await Navigator.pushReplacement(
|
await Navigator.pushReplacement(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => _timelineScreenRoute(
|
builder: (context) => _timelineScreenRoute(
|
||||||
configuration: config,
|
config: config,
|
||||||
context: context,
|
context: context,
|
||||||
|
initalCategory: category.title,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -221,7 +198,7 @@ Widget _postCreationScreenRoute({
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => _postOverviewScreenRoute(
|
builder: (context) => _postOverviewScreenRoute(
|
||||||
configuration: config,
|
config: config,
|
||||||
context: context,
|
context: context,
|
||||||
post: newPost,
|
post: newPost,
|
||||||
),
|
),
|
||||||
|
@ -232,7 +209,7 @@ Widget _postCreationScreenRoute({
|
||||||
onPostOverview: (post) async => Navigator.of(context).push(
|
onPostOverview: (post) async => Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => _postOverviewScreenRoute(
|
builder: (context) => _postOverviewScreenRoute(
|
||||||
configuration: config,
|
config: config,
|
||||||
context: context,
|
context: context,
|
||||||
post: post,
|
post: post,
|
||||||
),
|
),
|
||||||
|
@ -254,6 +231,7 @@ Widget _postCreationScreenRoute({
|
||||||
?.call(context, timelinePostCreationScreen, backButton) ??
|
?.call(context, timelinePostCreationScreen, backButton) ??
|
||||||
Scaffold(
|
Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
iconTheme: Theme.of(context).appBarTheme.iconTheme,
|
||||||
leading: backButton,
|
leading: backButton,
|
||||||
title: Text(
|
title: Text(
|
||||||
config.optionsBuilder(context).translations.postCreation,
|
config.optionsBuilder(context).translations.postCreation,
|
||||||
|
@ -277,17 +255,8 @@ Widget _postCreationScreenRoute({
|
||||||
Widget _postOverviewScreenRoute({
|
Widget _postOverviewScreenRoute({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required TimelinePost post,
|
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(
|
var timelinePostOverviewWidget = TimelinePostOverviewScreen(
|
||||||
options: config.optionsBuilder(context),
|
options: config.optionsBuilder(context),
|
||||||
service: config.service,
|
service: config.service,
|
||||||
|
@ -297,8 +266,11 @@ Widget _postOverviewScreenRoute({
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
await Navigator.of(context).pushAndRemoveUntil(
|
await Navigator.of(context).pushAndRemoveUntil(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) =>
|
builder: (context) => _timelineScreenRoute(
|
||||||
_timelineScreenRoute(configuration: config, context: context),
|
config: config,
|
||||||
|
context: context,
|
||||||
|
initalCategory: post.category,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
(route) => false,
|
(route) => false,
|
||||||
);
|
);
|
||||||
|
@ -320,6 +292,7 @@ Widget _postOverviewScreenRoute({
|
||||||
) ??
|
) ??
|
||||||
Scaffold(
|
Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
iconTheme: Theme.of(context).appBarTheme.iconTheme,
|
||||||
leading: backButton,
|
leading: backButton,
|
||||||
title: Text(
|
title: Text(
|
||||||
config.optionsBuilder(context).translations.postCreation,
|
config.optionsBuilder(context).translations.postCreation,
|
||||||
|
@ -336,17 +309,8 @@ Widget _postOverviewScreenRoute({
|
||||||
|
|
||||||
Widget _postCategorySelectionScreen({
|
Widget _postCategorySelectionScreen({
|
||||||
required BuildContext context,
|
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(
|
var timelineSelectionScreen = TimelineSelectionScreen(
|
||||||
postService: config.service.postService,
|
postService: config.service.postService,
|
||||||
options: config.optionsBuilder(context),
|
options: config.optionsBuilder(context),
|
||||||
|
@ -355,7 +319,7 @@ Widget _postCategorySelectionScreen({
|
||||||
await Navigator.of(context).push(
|
await Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => _postCreationScreenRoute(
|
builder: (context) => _postCreationScreenRoute(
|
||||||
configuration: config,
|
config: config,
|
||||||
context: context,
|
context: context,
|
||||||
category: category,
|
category: category,
|
||||||
),
|
),
|
||||||
|
@ -376,6 +340,7 @@ Widget _postCategorySelectionScreen({
|
||||||
?.call(context, timelineSelectionScreen) ??
|
?.call(context, timelineSelectionScreen) ??
|
||||||
Scaffold(
|
Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
iconTheme: Theme.of(context).appBarTheme.iconTheme,
|
||||||
leading: backButton,
|
leading: backButton,
|
||||||
title: Text(
|
title: Text(
|
||||||
config.optionsBuilder(context).translations.postCreation,
|
config.optionsBuilder(context).translations.postCreation,
|
||||||
|
|
|
@ -13,11 +13,28 @@ class TimelinePosterUserModel {
|
||||||
this.imageUrl,
|
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 userId;
|
||||||
final String? firstName;
|
final String? firstName;
|
||||||
final String? lastName;
|
final String? lastName;
|
||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
'first_name': firstName,
|
||||||
|
'last_name': lastName,
|
||||||
|
'image_url': imageUrl,
|
||||||
|
};
|
||||||
|
|
||||||
String? get fullName {
|
String? get fullName {
|
||||||
var fullName = '';
|
var fullName = '';
|
||||||
|
|
||||||
|
|
|
@ -160,6 +160,7 @@ class TimelineOptions {
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
Function() onPressed,
|
Function() onPressed,
|
||||||
String text,
|
String text,
|
||||||
|
TimelinePost post,
|
||||||
)? postOverviewButtonBuilder;
|
)? postOverviewButtonBuilder;
|
||||||
|
|
||||||
/// Optional builder to override the default alertdialog for post deletion
|
/// Optional builder to override the default alertdialog for post deletion
|
||||||
|
|
|
@ -61,6 +61,7 @@ class _TimelinePostCreationScreenState
|
||||||
void initState() {
|
void initState() {
|
||||||
titleController.addListener(_listenForInputs);
|
titleController.addListener(_listenForInputs);
|
||||||
contentController.addListener(_listenForInputs);
|
contentController.addListener(_listenForInputs);
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +78,7 @@ class _TimelinePostCreationScreenState
|
||||||
var imageRequired = widget.options.requireImageForPost;
|
var imageRequired = widget.options.requireImageForPost;
|
||||||
|
|
||||||
Future<void> onPostCreated() async {
|
Future<void> onPostCreated() async {
|
||||||
|
var user = await widget.service.userService?.getUser(widget.userId);
|
||||||
var post = TimelinePost(
|
var post = TimelinePost(
|
||||||
id: 'Post${Random().nextInt(1000)}',
|
id: 'Post${Random().nextInt(1000)}',
|
||||||
creatorId: widget.userId,
|
creatorId: widget.userId,
|
||||||
|
@ -89,6 +91,7 @@ class _TimelinePostCreationScreenState
|
||||||
createdAt: DateTime.now(),
|
createdAt: DateTime.now(),
|
||||||
reactionEnabled: allowComments,
|
reactionEnabled: allowComments,
|
||||||
image: image,
|
image: image,
|
||||||
|
creator: user,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (widget.enablePostOverviewScreen) {
|
if (widget.enablePostOverviewScreen) {
|
||||||
|
@ -362,7 +365,7 @@ class _TimelinePostCreationScreenState
|
||||||
child: DefaultFilledButton(
|
child: DefaultFilledButton(
|
||||||
onPressed: titleIsValid &&
|
onPressed: titleIsValid &&
|
||||||
contentIsValid &&
|
contentIsValid &&
|
||||||
(imageRequired ? image != null : true)
|
(!imageRequired || image != null)
|
||||||
? () async {
|
? () async {
|
||||||
if (formkey.currentState!
|
if (formkey.currentState!
|
||||||
.validate()) {
|
.validate()) {
|
||||||
|
|
|
@ -35,13 +35,18 @@ class TimelinePostOverviewScreen extends StatelessWidget {
|
||||||
options.postOverviewButtonBuilder?.call(
|
options.postOverviewButtonBuilder?.call(
|
||||||
context,
|
context,
|
||||||
() {
|
() {
|
||||||
|
if (isSubmitted) return;
|
||||||
|
isSubmitted = true;
|
||||||
onPostSubmit(timelinePost);
|
onPostSubmit(timelinePost);
|
||||||
},
|
},
|
||||||
options.translations.postIn,
|
options.translations.postIn,
|
||||||
|
timelinePost,
|
||||||
) ??
|
) ??
|
||||||
options.buttonBuilder?.call(
|
options.buttonBuilder?.call(
|
||||||
context,
|
context,
|
||||||
() {
|
() {
|
||||||
|
if (isSubmitted) return;
|
||||||
|
isSubmitted = true;
|
||||||
onPostSubmit(timelinePost);
|
onPostSubmit(timelinePost);
|
||||||
},
|
},
|
||||||
options.translations.postIn,
|
options.translations.postIn,
|
||||||
|
|
|
@ -36,6 +36,7 @@ class _TimelineSelectionScreenState extends State<TimelineSelectionScreen> {
|
||||||
padding: EdgeInsets.symmetric(
|
padding: EdgeInsets.symmetric(
|
||||||
horizontal: size.width * 0.05,
|
horizontal: size.width * 0.05,
|
||||||
),
|
),
|
||||||
|
child: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
@ -69,8 +70,8 @@ class _TimelineSelectionScreenState extends State<TimelineSelectionScreen> {
|
||||||
Theme.of(context).primaryColor,
|
Theme.of(context).primaryColor,
|
||||||
width: 2,
|
width: 2,
|
||||||
),
|
),
|
||||||
color: widget
|
color: widget.options.theme
|
||||||
.options.theme.categorySelectionButtonBackgroundColor,
|
.categorySelectionButtonBackgroundColor,
|
||||||
),
|
),
|
||||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||||
child: Column(
|
child: Column(
|
||||||
|
@ -78,7 +79,8 @@ class _TimelineSelectionScreenState extends State<TimelineSelectionScreen> {
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
padding:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 12.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
category.title,
|
category.title,
|
||||||
style: theme.textTheme.titleMedium,
|
style: theme.textTheme.titleMedium,
|
||||||
|
@ -97,13 +99,13 @@ class _TimelineSelectionScreenState extends State<TimelineSelectionScreen> {
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color:
|
color: widget
|
||||||
widget.options.theme.categorySelectionButtonBorderColor ??
|
.options.theme.categorySelectionButtonBorderColor ??
|
||||||
Theme.of(context).primaryColor,
|
Theme.of(context).primaryColor,
|
||||||
width: 2,
|
width: 2,
|
||||||
),
|
),
|
||||||
color:
|
color: widget
|
||||||
widget.options.theme.categorySelectionButtonBackgroundColor,
|
.options.theme.categorySelectionButtonBackgroundColor,
|
||||||
),
|
),
|
||||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||||
child: Column(
|
child: Column(
|
||||||
|
@ -136,6 +138,7 @@ class _TimelineSelectionScreenState extends State<TimelineSelectionScreen> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue