mirror of
https://github.com/Iconica-Development/flutter_timeline.git
synced 2025-05-19 10:33:44 +02:00
feat: add refreshindicator for postdetail
This commit is contained in:
parent
753ecc039e
commit
f587e81a4b
3 changed files with 253 additions and 221 deletions
|
@ -94,6 +94,23 @@ class FirebaseTimelineService with ChangeNotifier implements TimelineService {
|
||||||
return posts;
|
return posts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<TimelinePost> fetchPost(TimelinePost post) async {
|
||||||
|
var doc = await _db
|
||||||
|
.collection(_options.timelineCollectionName)
|
||||||
|
.doc(post.id)
|
||||||
|
.get();
|
||||||
|
var data = doc.data();
|
||||||
|
if (data == null) return post;
|
||||||
|
var user = await _userService.getUser(data['creator_id']);
|
||||||
|
var updatedPost = TimelinePost.fromJson(doc.id, data).copyWith(
|
||||||
|
creator: user,
|
||||||
|
);
|
||||||
|
_posts = _posts.map((p) => (p.id == post.id) ? updatedPost : p).toList();
|
||||||
|
notifyListeners();
|
||||||
|
return updatedPost;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<TimelinePost> getPosts(String? category) => _posts
|
List<TimelinePost> getPosts(String? category) => _posts
|
||||||
.where((element) => category == null || element.category == category)
|
.where((element) => category == null || element.category == category)
|
||||||
|
|
|
@ -12,6 +12,7 @@ abstract class TimelineService with ChangeNotifier {
|
||||||
Future<void> deletePost(TimelinePost post);
|
Future<void> deletePost(TimelinePost post);
|
||||||
Future<TimelinePost> createPost(TimelinePost post);
|
Future<TimelinePost> createPost(TimelinePost post);
|
||||||
Future<List<TimelinePost>> fetchPosts(String? category);
|
Future<List<TimelinePost>> fetchPosts(String? category);
|
||||||
|
Future<TimelinePost> fetchPost(TimelinePost post);
|
||||||
List<TimelinePost> getPosts(String? category);
|
List<TimelinePost> getPosts(String? category);
|
||||||
Future<TimelinePost> fetchPostDetails(TimelinePost post);
|
Future<TimelinePost> fetchPostDetails(TimelinePost post);
|
||||||
Future<TimelinePost> reactToPost(
|
Future<TimelinePost> reactToPost(
|
||||||
|
|
|
@ -111,7 +111,17 @@ class _TimelinePostScreenState extends State<TimelinePostScreen> {
|
||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
SingleChildScrollView(
|
RefreshIndicator(
|
||||||
|
onRefresh: () async {
|
||||||
|
updatePost(
|
||||||
|
await widget.service.fetchPostDetails(
|
||||||
|
await widget.service.fetchPost(
|
||||||
|
post,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: SingleChildScrollView(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: widget.padding,
|
padding: widget.padding,
|
||||||
child: Column(
|
child: Column(
|
||||||
|
@ -122,7 +132,8 @@ class _TimelinePostScreenState extends State<TimelinePostScreen> {
|
||||||
if (post.creator != null)
|
if (post.creator != null)
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: widget.onUserTap != null
|
onTap: widget.onUserTap != null
|
||||||
? () => widget.onUserTap?.call(post.creator!.userId)
|
? () =>
|
||||||
|
widget.onUserTap?.call(post.creator!.userId)
|
||||||
: null,
|
: null,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
@ -133,7 +144,8 @@ class _TimelinePostScreenState extends State<TimelinePostScreen> {
|
||||||
) ??
|
) ??
|
||||||
CircleAvatar(
|
CircleAvatar(
|
||||||
radius: 20,
|
radius: 20,
|
||||||
backgroundImage: CachedNetworkImageProvider(
|
backgroundImage:
|
||||||
|
CachedNetworkImageProvider(
|
||||||
post.creator!.imageUrl!,
|
post.creator!.imageUrl!,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -307,7 +319,8 @@ class _TimelinePostScreenState extends State<TimelinePostScreen> {
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
reaction.creator?.fullName ??
|
reaction.creator?.fullName ??
|
||||||
widget.options.translations.anonymousUser,
|
widget
|
||||||
|
.options.translations.anonymousUser,
|
||||||
style: theme.textTheme.titleSmall,
|
style: theme.textTheme.titleSmall,
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
|
@ -348,6 +361,7 @@ class _TimelinePostScreenState extends State<TimelinePostScreen> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
if (post.reactionEnabled)
|
if (post.reactionEnabled)
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
|
|
Loading…
Reference in a new issue