From 21a1998946726bc337a6b7d14043e2fe39909ee4 Mon Sep 17 00:00:00 2001 From: Elias Bonnici Date: Tue, 16 Apr 2024 13:07:16 +0200 Subject: [PATCH 1/2] Add overflow and tooltip to `ActionItem` --- lib/app/views/action_list.dart | 17 ++++++++++++++--- lib/widgets/tooltip_if_truncated.dart | 12 +++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/app/views/action_list.dart b/lib/app/views/action_list.dart index 3c5f4034..003c5ed7 100644 --- a/lib/app/views/action_list.dart +++ b/lib/app/views/action_list.dart @@ -19,6 +19,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../core/state.dart'; import '../../widgets/list_title.dart'; +import '../../widgets/tooltip_if_truncated.dart'; import '../models.dart'; class ActionListItem extends StatelessWidget { @@ -51,15 +52,25 @@ class ActionListItem extends StatelessWidget { // ActionStyle.primary => (theme.onPrimary, theme.primary), // ActionStyle.error => (theme.onError, theme.error), // }; + final theme = Theme.of(context); return ListTile( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(48)), - title: Text(title), - subtitle: subtitle != null ? Text(subtitle!) : null, + title: TooltipIfTruncated( + text: title, + style: TextStyle(fontSize: theme.textTheme.bodyLarge!.fontSize), + ), + subtitle: subtitle != null + ? TooltipIfTruncated( + text: subtitle!, + style: TextStyle(fontSize: theme.textTheme.bodyMedium!.fontSize), + maxLines: 2, + ) + : null, leading: Opacity( opacity: onTap != null ? 1.0 : 0.4, child: CircleAvatar( - foregroundColor: Theme.of(context).colorScheme.onSurfaceVariant, + foregroundColor: theme.colorScheme.onSurfaceVariant, backgroundColor: Colors.transparent, child: icon, ), diff --git a/lib/widgets/tooltip_if_truncated.dart b/lib/widgets/tooltip_if_truncated.dart index 2eaaf932..1f5fe07c 100644 --- a/lib/widgets/tooltip_if_truncated.dart +++ b/lib/widgets/tooltip_if_truncated.dart @@ -20,8 +20,13 @@ class TooltipIfTruncated extends StatelessWidget { final String text; final TextStyle style; final String? tooltip; + final int maxLines; const TooltipIfTruncated( - {super.key, required this.text, required this.style, this.tooltip}); + {super.key, + required this.text, + required this.style, + this.tooltip, + this.maxLines = 1}); @override Widget build(BuildContext context) { @@ -31,13 +36,14 @@ class TooltipIfTruncated extends StatelessWidget { text, textAlign: TextAlign.left, overflow: TextOverflow.fade, - softWrap: false, + maxLines: maxLines, + softWrap: maxLines != 1, style: style, ); final TextPainter textPainter = TextPainter( text: TextSpan(text: text, style: style), textDirection: TextDirection.ltr, - maxLines: 1, + maxLines: maxLines, )..layout(minWidth: 0, maxWidth: constraints.maxWidth); return textPainter.didExceedMaxLines ? Tooltip( From 4cf5296de2f561951f246b88f75c25deb32ea739 Mon Sep 17 00:00:00 2001 From: Elias Bonnici Date: Tue, 16 Apr 2024 16:19:24 +0200 Subject: [PATCH 2/2] Use ellipsis overflow for `subTitle` in `ActionItem` --- lib/app/views/action_list.dart | 1 + lib/widgets/tooltip_if_truncated.dart | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/app/views/action_list.dart b/lib/app/views/action_list.dart index 003c5ed7..9e830684 100644 --- a/lib/app/views/action_list.dart +++ b/lib/app/views/action_list.dart @@ -65,6 +65,7 @@ class ActionListItem extends StatelessWidget { text: subtitle!, style: TextStyle(fontSize: theme.textTheme.bodyMedium!.fontSize), maxLines: 2, + overflow: TextOverflow.ellipsis, ) : null, leading: Opacity( diff --git a/lib/widgets/tooltip_if_truncated.dart b/lib/widgets/tooltip_if_truncated.dart index 1f5fe07c..a85f052b 100644 --- a/lib/widgets/tooltip_if_truncated.dart +++ b/lib/widgets/tooltip_if_truncated.dart @@ -21,12 +21,14 @@ class TooltipIfTruncated extends StatelessWidget { final TextStyle style; final String? tooltip; final int maxLines; + final TextOverflow overflow; const TooltipIfTruncated( {super.key, required this.text, required this.style, this.tooltip, - this.maxLines = 1}); + this.maxLines = 1, + this.overflow = TextOverflow.fade}); @override Widget build(BuildContext context) { @@ -35,7 +37,7 @@ class TooltipIfTruncated extends StatelessWidget { final textWidget = Text( text, textAlign: TextAlign.left, - overflow: TextOverflow.fade, + overflow: overflow, maxLines: maxLines, softWrap: maxLines != 1, style: style,