2021-03-17 16:04:45 +00:00
|
|
|
import 'package:comunic/enums/post_target.dart';
|
|
|
|
import 'package:comunic/helpers/posts_helper.dart';
|
|
|
|
import 'package:comunic/models/advanced_user_info.dart';
|
|
|
|
import 'package:comunic/ui/widgets/post_create_form_widget.dart';
|
|
|
|
import 'package:comunic/ui/widgets/posts_list_widget.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
/// User posts
|
|
|
|
///
|
|
|
|
/// @author Pierre Hubert
|
|
|
|
|
|
|
|
class UserPostsSection extends StatefulWidget {
|
|
|
|
final AdvancedUserInfo user;
|
|
|
|
|
|
|
|
const UserPostsSection({
|
2022-03-10 18:39:57 +00:00
|
|
|
Key? key,
|
|
|
|
required this.user,
|
2022-03-11 15:40:56 +00:00
|
|
|
}) : super(key: key);
|
2021-03-17 16:04:45 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
_UserPostsSectionState createState() => _UserPostsSectionState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UserPostsSectionState extends State<UserPostsSection> {
|
2022-03-10 18:39:57 +00:00
|
|
|
int? get _userID => widget.user.id;
|
2021-03-17 16:04:45 +00:00
|
|
|
|
|
|
|
final _postsKey = GlobalKey<PostsListWidgetState>();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) => PostsListWidget(
|
2021-12-28 16:15:25 +00:00
|
|
|
key: _postsKey,
|
2021-03-17 16:04:45 +00:00
|
|
|
topWidgets: [
|
|
|
|
widget.user.canPostTexts
|
|
|
|
? PostCreateFormWidget(
|
|
|
|
postTarget: PostTarget.USER_PAGE,
|
2022-03-10 18:39:57 +00:00
|
|
|
targetID: _userID!,
|
2021-03-17 16:04:45 +00:00
|
|
|
onCreated: _postCreated,
|
|
|
|
)
|
|
|
|
: Container()
|
|
|
|
],
|
|
|
|
getPostsList: () => PostsHelper().getUserPosts(_userID),
|
|
|
|
getOlder: (from) => PostsHelper().getUserPosts(_userID, from: from),
|
|
|
|
showPostsTarget: false,
|
|
|
|
);
|
|
|
|
|
|
|
|
void _postCreated() {
|
2022-03-10 18:39:57 +00:00
|
|
|
_postsKey.currentState!.loadPostsList(getOlder: false);
|
2021-03-17 16:04:45 +00:00
|
|
|
}
|
|
|
|
}
|