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
|
@override
|
||||||
Future<TimelinePost> createPost(TimelinePost post) async {
|
Future<TimelinePost> createPost(TimelinePost post) async {
|
||||||
var postId = const Uuid().v4();
|
var postId = const Uuid().v4();
|
||||||
var imageRef =
|
var updatedPost = post.copyWith(id: postId);
|
||||||
_storage.ref().child('${_options.timelineCollectionName}/$postId');
|
if (post.image != null) {
|
||||||
var result = await imageRef.putData(post.image!);
|
var imageRef =
|
||||||
var imageUrl = await result.ref.getDownloadURL();
|
_storage.ref().child('${_options.timelineCollectionName}/$postId');
|
||||||
var updatedPost = post.copyWith(imageUrl: imageUrl, id: postId);
|
var result = await imageRef.putData(post.image!);
|
||||||
|
var imageUrl = await result.ref.getDownloadURL();
|
||||||
|
updatedPost = updatedPost.copyWith(imageUrl: imageUrl);
|
||||||
|
}
|
||||||
var postRef =
|
var postRef =
|
||||||
_db.collection(_options.timelineCollectionName).doc(updatedPost.id);
|
_db.collection(_options.timelineCollectionName).doc(updatedPost.id);
|
||||||
await postRef.set(updatedPost.toJson());
|
await postRef.set(updatedPost.toJson());
|
||||||
|
@ -74,7 +77,7 @@ class FirebaseTimelineService with ChangeNotifier implements TimelineService {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<TimelinePost>> fetchPosts(String? category) async {
|
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)
|
var snapshot = (category != null)
|
||||||
? await _db
|
? await _db
|
||||||
.collection(_options.timelineCollectionName)
|
.collection(_options.timelineCollectionName)
|
||||||
|
|
|
@ -66,9 +66,8 @@ class _TimelinePostCreationScreenState
|
||||||
|
|
||||||
void checkIfEditingDone() {
|
void checkIfEditingDone() {
|
||||||
setState(() {
|
setState(() {
|
||||||
editingDone = titleController.text.isNotEmpty &&
|
editingDone =
|
||||||
contentController.text.isNotEmpty &&
|
titleController.text.isNotEmpty && contentController.text.isNotEmpty;
|
||||||
image != null;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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),
|
const SizedBox(height: 120),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
|
@ -19,7 +19,7 @@ class TimelineScreen extends StatefulWidget {
|
||||||
this.posts,
|
this.posts,
|
||||||
this.controller,
|
this.controller,
|
||||||
this.timelineCategoryFilter,
|
this.timelineCategoryFilter,
|
||||||
this.timelinePostHeight = 100.0,
|
this.timelinePostHeight,
|
||||||
this.padding = const EdgeInsets.symmetric(vertical: 12.0),
|
this.padding = const EdgeInsets.symmetric(vertical: 12.0),
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
@ -39,7 +39,7 @@ class TimelineScreen extends StatefulWidget {
|
||||||
final String? timelineCategoryFilter;
|
final String? timelineCategoryFilter;
|
||||||
|
|
||||||
/// The height of a post in the timeline
|
/// 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
|
/// This is used if you want to pass in a list of posts instead
|
||||||
/// of fetching them from the service
|
/// of fetching them from the service
|
||||||
|
|
|
@ -26,7 +26,9 @@ class TimelinePostWidget extends StatelessWidget {
|
||||||
final TimelineOptions options;
|
final TimelineOptions options;
|
||||||
|
|
||||||
final TimelinePost post;
|
final TimelinePost post;
|
||||||
final double height;
|
|
||||||
|
/// Optional max height of the post
|
||||||
|
final double? height;
|
||||||
final VoidCallback onTap;
|
final VoidCallback onTap;
|
||||||
final VoidCallback onTapLike;
|
final VoidCallback onTapLike;
|
||||||
final VoidCallback onTapUnlike;
|
final VoidCallback onTapUnlike;
|
||||||
|
@ -41,7 +43,8 @@ class TimelinePostWidget extends StatelessWidget {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: height,
|
// TODO(anyone): should posts with text have a max height?
|
||||||
|
height: post.imageUrl != null ? height : null,
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
@ -114,6 +117,7 @@ class TimelinePostWidget extends StatelessWidget {
|
||||||
// image of the post
|
// image of the post
|
||||||
if (post.imageUrl != null) ...[
|
if (post.imageUrl != null) ...[
|
||||||
Flexible(
|
Flexible(
|
||||||
|
flex: height != null ? 1 : 0,
|
||||||
child: CachedNetworkImage(
|
child: CachedNetworkImage(
|
||||||
imageUrl: post.imageUrl!,
|
imageUrl: post.imageUrl!,
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
|
|
Loading…
Reference in a new issue