feat: make postheight optional

This commit is contained in:
Freek van de Ven 2023-11-21 23:19:48 +01:00
parent f587e81a4b
commit a16c77be0e
5 changed files with 25 additions and 13 deletions

View file

@ -35,11 +35,14 @@ class FirebaseTimelineService with ChangeNotifier implements TimelineService {
@override
Future<TimelinePost> 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<List<TimelinePost>> 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)

View file

@ -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;
});
}

View file

@ -355,6 +355,12 @@ class _TimelinePostScreenState extends State<TimelinePostScreen> {
],
),
],
if (post.reactions?.isEmpty ?? true) ...[
const SizedBox(height: 16),
Text(
widget.options.translations.firstComment,
),
],
const SizedBox(height: 120),
],
],

View file

@ -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

View file

@ -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,