This commit is contained in:
Jacques 2024-01-18 11:20:53 +01:00
parent e61da6873d
commit 06ea5f0281
3 changed files with 50 additions and 40 deletions

View file

@ -39,6 +39,8 @@ class TimelineOptions {
this.nameBuilder, this.nameBuilder,
this.padding = const EdgeInsets.symmetric(vertical: 12.0), this.padding = const EdgeInsets.symmetric(vertical: 12.0),
this.iconSize = 26, this.iconSize = 26,
this.postWidgetheight,
this.postPadding = const EdgeInsets.all(12.0),
}); });
/// Theming options for the timeline /// Theming options for the timeline
@ -105,6 +107,12 @@ class TimelineOptions {
/// Size of icons like the comment and like icons. Dafualts to 26 /// Size of icons like the comment and like icons. Dafualts to 26
final double iconSize; final double iconSize;
/// Sets a predefined height for the postWidget.
final double? postWidgetheight;
/// Padding of each post
final EdgeInsets postPadding;
} }
typedef ButtonBuilder = Widget Function( typedef ButtonBuilder = Widget Function(

View file

@ -18,6 +18,7 @@ class TimelineScreen extends StatefulWidget {
this.onUserTap, this.onUserTap,
this.posts, this.posts,
this.timelineCategoryFilter, this.timelineCategoryFilter,
this.postWidget,
super.key, super.key,
}); });
@ -46,6 +47,9 @@ class TimelineScreen extends StatefulWidget {
/// If this is not null, the user can tap on the user avatar or name /// If this is not null, the user can tap on the user avatar or name
final Function(String userId)? onUserTap; final Function(String userId)? onUserTap;
/// Override the standard postwidget
final Widget Function(TimelinePost post)? postWidget;
@override @override
State<TimelineScreen> createState() => _TimelineScreenState(); State<TimelineScreen> createState() => _TimelineScreenState();
} }
@ -95,13 +99,13 @@ class _TimelineScreenState extends State<TimelineScreen> {
children: [ children: [
...posts.map( ...posts.map(
(post) => Padding( (post) => Padding(
padding: widget.options.padding, padding: widget.options.postPadding,
child: TimelinePostWidget( child: widget.postWidget?.call(post) ??
TimelinePostWidget(
service: widget.service, service: widget.service,
userId: widget.userId, userId: widget.userId,
options: widget.options, options: widget.options,
post: post, post: post,
height: widget.options.timelinePostHeight,
onTap: () async { onTap: () async {
if (widget.onPostTap != null) { if (widget.onPostTap != null) {
widget.onPostTap!.call(post); widget.onPostTap!.call(post);

View file

@ -13,7 +13,6 @@ class TimelinePostWidget extends StatefulWidget {
required this.userId, required this.userId,
required this.options, required this.options,
required this.post, required this.post,
required this.height,
required this.onTap, required this.onTap,
required this.onTapLike, required this.onTapLike,
required this.onTapUnlike, required this.onTapUnlike,
@ -30,7 +29,6 @@ class TimelinePostWidget extends StatefulWidget {
final TimelinePost post; final TimelinePost post;
/// Optional max height of the post /// 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;
@ -51,7 +49,7 @@ class _TimelinePostWidgetState extends State<TimelinePostWidget> {
return InkWell( return InkWell(
onTap: widget.onTap, onTap: widget.onTap,
child: SizedBox( child: SizedBox(
height: widget.post.imageUrl != null ? widget.height : null, height: widget.post.imageUrl != null ? widget.options.postWidgetheight : null,
width: double.infinity, width: double.infinity,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -145,7 +143,7 @@ class _TimelinePostWidgetState extends State<TimelinePostWidget> {
if (widget.post.imageUrl != null) ...[ if (widget.post.imageUrl != null) ...[
const SizedBox(height: 8), const SizedBox(height: 8),
Flexible( Flexible(
flex: widget.height != null ? 1 : 0, flex: widget.options.postWidgetheight != null ? 1 : 0,
child: ClipRRect( child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(8)), borderRadius: const BorderRadius.all(Radius.circular(8)),
child: widget.options.doubleTapTolike child: widget.options.doubleTapTolike