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,
}); });
@ -30,7 +31,7 @@ class TimelineScreen extends StatefulWidget {
/// All the configuration options for the timelinescreens and widgets /// All the configuration options for the timelinescreens and widgets
final TimelineOptions options; final TimelineOptions options;
/// The controller for the scroll view /// The controller for the scroll view
final ScrollController? scrollController; final ScrollController? scrollController;
/// The string to filter the timeline by category /// 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 /// 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,43 +99,43 @@ 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) ??
service: widget.service, TimelinePostWidget(
userId: widget.userId, service: widget.service,
options: widget.options, userId: widget.userId,
post: post, options: widget.options,
height: widget.options.timelinePostHeight, post: post,
onTap: () async { onTap: () async {
if (widget.onPostTap != null) { if (widget.onPostTap != null) {
widget.onPostTap!.call(post); widget.onPostTap!.call(post);
return; return;
} }
await Navigator.push( await Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => Scaffold( builder: (context) => Scaffold(
body: TimelinePostScreen( body: TimelinePostScreen(
userId: widget.userId, userId: widget.userId,
service: widget.service, service: widget.service,
options: widget.options, options: widget.options,
post: post, post: post,
onPostDelete: () { onPostDelete: () {
widget.service.deletePost(post); widget.service.deletePost(post);
}, },
),
),
), ),
), );
), },
); onTapLike: () async =>
}, service.likePost(widget.userId, post),
onTapLike: () async => onTapUnlike: () async =>
service.likePost(widget.userId, post), service.unlikePost(widget.userId, post),
onTapUnlike: () async => onPostDelete: () async => service.deletePost(post),
service.unlikePost(widget.userId, post), onUserTap: widget.onUserTap,
onPostDelete: () async => service.deletePost(post), ),
onUserTap: widget.onUserTap,
),
), ),
), ),
if (posts.isEmpty) if (posts.isEmpty)

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