From 06ea5f028164627a7d1ece92213dab29bc32531a Mon Sep 17 00:00:00 2001 From: Jacques Date: Thu, 18 Jan 2024 11:20:53 +0100 Subject: [PATCH] merge --- .../lib/src/config/timeline_options.dart | 8 ++ .../lib/src/screens/timeline_screen.dart | 76 ++++++++++--------- .../lib/src/widgets/timeline_post_widget.dart | 6 +- 3 files changed, 50 insertions(+), 40 deletions(-) diff --git a/packages/flutter_timeline_view/lib/src/config/timeline_options.dart b/packages/flutter_timeline_view/lib/src/config/timeline_options.dart index 5972a49..f5dfcdd 100644 --- a/packages/flutter_timeline_view/lib/src/config/timeline_options.dart +++ b/packages/flutter_timeline_view/lib/src/config/timeline_options.dart @@ -39,6 +39,8 @@ class TimelineOptions { this.nameBuilder, this.padding = const EdgeInsets.symmetric(vertical: 12.0), this.iconSize = 26, + this.postWidgetheight, + this.postPadding = const EdgeInsets.all(12.0), }); /// Theming options for the timeline @@ -105,6 +107,12 @@ class TimelineOptions { /// Size of icons like the comment and like icons. Dafualts to 26 final double iconSize; + + /// Sets a predefined height for the postWidget. + final double? postWidgetheight; + + /// Padding of each post + final EdgeInsets postPadding; } typedef ButtonBuilder = Widget Function( 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 d8f9a10..e025a9b 100644 --- a/packages/flutter_timeline_view/lib/src/screens/timeline_screen.dart +++ b/packages/flutter_timeline_view/lib/src/screens/timeline_screen.dart @@ -18,6 +18,7 @@ class TimelineScreen extends StatefulWidget { this.onUserTap, this.posts, this.timelineCategoryFilter, + this.postWidget, super.key, }); @@ -30,7 +31,7 @@ class TimelineScreen extends StatefulWidget { /// All the configuration options for the timelinescreens and widgets final TimelineOptions options; - /// The controller for the scroll view + /// The controller for the scroll view final ScrollController? scrollController; /// The string to filter the timeline by category @@ -46,6 +47,9 @@ class TimelineScreen extends StatefulWidget { /// If this is not null, the user can tap on the user avatar or name final Function(String userId)? onUserTap; + /// Override the standard postwidget + final Widget Function(TimelinePost post)? postWidget; + @override State createState() => _TimelineScreenState(); } @@ -95,43 +99,43 @@ class _TimelineScreenState extends State { children: [ ...posts.map( (post) => Padding( - padding: widget.options.padding, - child: TimelinePostWidget( - service: widget.service, - userId: widget.userId, - options: widget.options, - post: post, - height: widget.options.timelinePostHeight, - onTap: () async { - if (widget.onPostTap != null) { - widget.onPostTap!.call(post); - return; - } + padding: widget.options.postPadding, + child: widget.postWidget?.call(post) ?? + TimelinePostWidget( + service: widget.service, + userId: widget.userId, + options: widget.options, + post: post, + onTap: () async { + if (widget.onPostTap != null) { + widget.onPostTap!.call(post); + return; + } - await Navigator.push( - context, - MaterialPageRoute( - builder: (context) => Scaffold( - body: TimelinePostScreen( - userId: widget.userId, - service: widget.service, - options: widget.options, - post: post, - onPostDelete: () { - widget.service.deletePost(post); - }, + await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => Scaffold( + body: TimelinePostScreen( + userId: widget.userId, + service: widget.service, + options: widget.options, + post: post, + onPostDelete: () { + widget.service.deletePost(post); + }, + ), + ), ), - ), - ), - ); - }, - onTapLike: () async => - service.likePost(widget.userId, post), - onTapUnlike: () async => - service.unlikePost(widget.userId, post), - onPostDelete: () async => service.deletePost(post), - onUserTap: widget.onUserTap, - ), + ); + }, + onTapLike: () async => + service.likePost(widget.userId, post), + onTapUnlike: () async => + service.unlikePost(widget.userId, post), + onPostDelete: () async => service.deletePost(post), + onUserTap: widget.onUserTap, + ), ), ), if (posts.isEmpty) 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 ea86de1..06ec2ae 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 @@ -13,7 +13,6 @@ class TimelinePostWidget extends StatefulWidget { required this.userId, required this.options, required this.post, - required this.height, required this.onTap, required this.onTapLike, required this.onTapUnlike, @@ -30,7 +29,6 @@ class TimelinePostWidget extends StatefulWidget { final TimelinePost post; /// Optional max height of the post - final double? height; final VoidCallback onTap; final VoidCallback onTapLike; final VoidCallback onTapUnlike; @@ -51,7 +49,7 @@ class _TimelinePostWidgetState extends State { return InkWell( onTap: widget.onTap, child: SizedBox( - height: widget.post.imageUrl != null ? widget.height : null, + height: widget.post.imageUrl != null ? widget.options.postWidgetheight : null, width: double.infinity, child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -145,7 +143,7 @@ class _TimelinePostWidgetState extends State { if (widget.post.imageUrl != null) ...[ const SizedBox(height: 8), Flexible( - flex: widget.height != null ? 1 : 0, + flex: widget.options.postWidgetheight != null ? 1 : 0, child: ClipRRect( borderRadius: const BorderRadius.all(Radius.circular(8)), child: widget.options.doubleTapTolike