mirror of
https://github.com/Iconica-Development/flutter_timeline.git
synced 2025-05-19 10:33:44 +02:00
feat: make postheight optional
This commit is contained in:
parent
f587e81a4b
commit
a16c77be0e
5 changed files with 25 additions and 13 deletions
|
@ -35,11 +35,14 @@ class FirebaseTimelineService with ChangeNotifier implements TimelineService {
|
|||
@override
|
||||
Future<TimelinePost> createPost(TimelinePost post) async {
|
||||
var postId = const Uuid().v4();
|
||||
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();
|
||||
var updatedPost = post.copyWith(imageUrl: imageUrl, id: postId);
|
||||
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)
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
],
|
||||
],
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue