From a16c77be0ebb76b8f4ec9d148cad0809d4067519 Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Tue, 21 Nov 2023 23:19:48 +0100 Subject: [PATCH] feat: make postheight optional --- .../src/service/firebase_timeline_service.dart | 15 +++++++++------ .../screens/timeline_post_creation_screen.dart | 5 ++--- .../lib/src/screens/timeline_post_screen.dart | 6 ++++++ .../lib/src/screens/timeline_screen.dart | 4 ++-- .../lib/src/widgets/timeline_post_widget.dart | 8 ++++++-- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/packages/flutter_timeline_firebase/lib/src/service/firebase_timeline_service.dart b/packages/flutter_timeline_firebase/lib/src/service/firebase_timeline_service.dart index 523df2b..9a8248a 100644 --- a/packages/flutter_timeline_firebase/lib/src/service/firebase_timeline_service.dart +++ b/packages/flutter_timeline_firebase/lib/src/service/firebase_timeline_service.dart @@ -35,11 +35,14 @@ class FirebaseTimelineService with ChangeNotifier implements TimelineService { @override Future createPost(TimelinePost post) async { var postId = const Uuid().v4(); - var imageRef = - _storage.ref().child('${_options.timelineCollectionName}/$postId'); - var result = await imageRef.putData(post.image!); - var imageUrl = await result.ref.getDownloadURL(); - var updatedPost = post.copyWith(imageUrl: imageUrl, id: postId); + var updatedPost = post.copyWith(id: postId); + if (post.image != null) { + var imageRef = + _storage.ref().child('${_options.timelineCollectionName}/$postId'); + var result = await imageRef.putData(post.image!); + var imageUrl = await result.ref.getDownloadURL(); + updatedPost = updatedPost.copyWith(imageUrl: imageUrl); + } var postRef = _db.collection(_options.timelineCollectionName).doc(updatedPost.id); await postRef.set(updatedPost.toJson()); @@ -74,7 +77,7 @@ class FirebaseTimelineService with ChangeNotifier implements TimelineService { @override Future> fetchPosts(String? category) async { - debugPrint('fetching posts from firebase $category!!!'); + debugPrint('fetching posts from firebase with category: $category'); var snapshot = (category != null) ? await _db .collection(_options.timelineCollectionName) diff --git a/packages/flutter_timeline_view/lib/src/screens/timeline_post_creation_screen.dart b/packages/flutter_timeline_view/lib/src/screens/timeline_post_creation_screen.dart index 44a2c71..19c639f 100644 --- a/packages/flutter_timeline_view/lib/src/screens/timeline_post_creation_screen.dart +++ b/packages/flutter_timeline_view/lib/src/screens/timeline_post_creation_screen.dart @@ -66,9 +66,8 @@ class _TimelinePostCreationScreenState void checkIfEditingDone() { setState(() { - editingDone = titleController.text.isNotEmpty && - contentController.text.isNotEmpty && - image != null; + editingDone = + titleController.text.isNotEmpty && contentController.text.isNotEmpty; }); } diff --git a/packages/flutter_timeline_view/lib/src/screens/timeline_post_screen.dart b/packages/flutter_timeline_view/lib/src/screens/timeline_post_screen.dart index 46a4444..ff77b5f 100644 --- a/packages/flutter_timeline_view/lib/src/screens/timeline_post_screen.dart +++ b/packages/flutter_timeline_view/lib/src/screens/timeline_post_screen.dart @@ -355,6 +355,12 @@ class _TimelinePostScreenState extends State { ], ), ], + if (post.reactions?.isEmpty ?? true) ...[ + const SizedBox(height: 16), + Text( + widget.options.translations.firstComment, + ), + ], const SizedBox(height: 120), ], ], diff --git a/packages/flutter_timeline_view/lib/src/screens/timeline_screen.dart b/packages/flutter_timeline_view/lib/src/screens/timeline_screen.dart index 7b07a72..85a60a2 100644 --- a/packages/flutter_timeline_view/lib/src/screens/timeline_screen.dart +++ b/packages/flutter_timeline_view/lib/src/screens/timeline_screen.dart @@ -19,7 +19,7 @@ class TimelineScreen extends StatefulWidget { this.posts, this.controller, this.timelineCategoryFilter, - this.timelinePostHeight = 100.0, + this.timelinePostHeight, this.padding = const EdgeInsets.symmetric(vertical: 12.0), super.key, }); @@ -39,7 +39,7 @@ class TimelineScreen extends StatefulWidget { final String? timelineCategoryFilter; /// The height of a post in the timeline - final double timelinePostHeight; + final double? timelinePostHeight; /// This is used if you want to pass in a list of posts instead /// of fetching them from the service diff --git a/packages/flutter_timeline_view/lib/src/widgets/timeline_post_widget.dart b/packages/flutter_timeline_view/lib/src/widgets/timeline_post_widget.dart index 4ee162b..8bb570f 100644 --- a/packages/flutter_timeline_view/lib/src/widgets/timeline_post_widget.dart +++ b/packages/flutter_timeline_view/lib/src/widgets/timeline_post_widget.dart @@ -26,7 +26,9 @@ class TimelinePostWidget extends StatelessWidget { final TimelineOptions options; final TimelinePost post; - final double height; + + /// Optional max height of the post + final double? height; final VoidCallback onTap; final VoidCallback onTapLike; final VoidCallback onTapUnlike; @@ -41,7 +43,8 @@ class TimelinePostWidget extends StatelessWidget { return InkWell( onTap: onTap, child: SizedBox( - height: height, + // TODO(anyone): should posts with text have a max height? + height: post.imageUrl != null ? height : null, width: double.infinity, child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -114,6 +117,7 @@ class TimelinePostWidget extends StatelessWidget { // image of the post if (post.imageUrl != null) ...[ Flexible( + flex: height != null ? 1 : 0, child: CachedNetworkImage( imageUrl: post.imageUrl!, width: double.infinity,