This commit is contained in:
Elias Bonnici 2024-04-16 16:35:32 +02:00
commit 0349b37065
No known key found for this signature in database
GPG Key ID: 5EAC28EA3F980CCF
2 changed files with 27 additions and 7 deletions

View File

@ -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,26 @@ 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,
overflow: TextOverflow.ellipsis,
)
: 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,
),

View File

@ -20,8 +20,15 @@ class TooltipIfTruncated extends StatelessWidget {
final String text;
final TextStyle style;
final String? tooltip;
final int maxLines;
final TextOverflow overflow;
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,
this.overflow = TextOverflow.fade});
@override
Widget build(BuildContext context) {
@ -30,14 +37,15 @@ class TooltipIfTruncated extends StatelessWidget {
final textWidget = Text(
text,
textAlign: TextAlign.left,
overflow: TextOverflow.fade,
softWrap: false,
overflow: overflow,
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(