Skip to content

Commit 21a1998

Browse files
committed
Add overflow and tooltip to ActionItem
1 parent 059fdbf commit 21a1998

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

lib/app/views/action_list.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
1919

2020
import '../../core/state.dart';
2121
import '../../widgets/list_title.dart';
22+
import '../../widgets/tooltip_if_truncated.dart';
2223
import '../models.dart';
2324

2425
class ActionListItem extends StatelessWidget {
@@ -51,15 +52,25 @@ class ActionListItem extends StatelessWidget {
5152
// ActionStyle.primary => (theme.onPrimary, theme.primary),
5253
// ActionStyle.error => (theme.onError, theme.error),
5354
// };
55+
final theme = Theme.of(context);
5456

5557
return ListTile(
5658
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(48)),
57-
title: Text(title),
58-
subtitle: subtitle != null ? Text(subtitle!) : null,
59+
title: TooltipIfTruncated(
60+
text: title,
61+
style: TextStyle(fontSize: theme.textTheme.bodyLarge!.fontSize),
62+
),
63+
subtitle: subtitle != null
64+
? TooltipIfTruncated(
65+
text: subtitle!,
66+
style: TextStyle(fontSize: theme.textTheme.bodyMedium!.fontSize),
67+
maxLines: 2,
68+
)
69+
: null,
5970
leading: Opacity(
6071
opacity: onTap != null ? 1.0 : 0.4,
6172
child: CircleAvatar(
62-
foregroundColor: Theme.of(context).colorScheme.onSurfaceVariant,
73+
foregroundColor: theme.colorScheme.onSurfaceVariant,
6374
backgroundColor: Colors.transparent,
6475
child: icon,
6576
),

lib/widgets/tooltip_if_truncated.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ class TooltipIfTruncated extends StatelessWidget {
2020
final String text;
2121
final TextStyle style;
2222
final String? tooltip;
23+
final int maxLines;
2324
const TooltipIfTruncated(
24-
{super.key, required this.text, required this.style, this.tooltip});
25+
{super.key,
26+
required this.text,
27+
required this.style,
28+
this.tooltip,
29+
this.maxLines = 1});
2530

2631
@override
2732
Widget build(BuildContext context) {
@@ -31,13 +36,14 @@ class TooltipIfTruncated extends StatelessWidget {
3136
text,
3237
textAlign: TextAlign.left,
3338
overflow: TextOverflow.fade,
34-
softWrap: false,
39+
maxLines: maxLines,
40+
softWrap: maxLines != 1,
3541
style: style,
3642
);
3743
final TextPainter textPainter = TextPainter(
3844
text: TextSpan(text: text, style: style),
3945
textDirection: TextDirection.ltr,
40-
maxLines: 1,
46+
maxLines: maxLines,
4147
)..layout(minWidth: 0, maxWidth: constraints.maxWidth);
4248
return textPainter.didExceedMaxLines
4349
? Tooltip(

0 commit comments

Comments
 (0)