reorganize and rename widgets

This commit is contained in:
Henry Hiles 2026-11-09 17:25:02 -05:00
commit d5f29dc344
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -0,0 +1,72 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:material_ui/material_ui.dart";
/// A line of what a state event changed, like a room's old name, struck
/// through, then its new one.
class const ChangeLine({
/// What changed, e.g. `Denied`, in bold before the items.
final String? label,
final IList<String> removed = const .empty(),
final IList<String> added = const .empty(),
required final Color removedColor,
required final Color addedColor,
/// Whether to quote the items, like server names, but not whole sentences.
final bool quoted = true,
/// Shown after the items, like a change that isn't one of them.
final List<Widget> trailing = const [],
/// How many removed and how many added items to show, as some events, like
/// a room's first server ACL, can change hundreds.
final int maxShown = 5,
/// The most lines each item can take, as some, like topics, can be long.
final int maxLines = 2,
super.key,
}) extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final style = theme.textTheme.labelMedium;
Iterable<Widget> items(
IList<String> items, {
required Color color,
required bool struck,
}) => [
...items
.take(maxShown)
.map(
(item) => Text(
quoted ? "\"$item\"" : item,
maxLines: maxLines,
overflow: .ellipsis,
style: style?.copyWith(
color: color,
decoration: struck ? .lineThrough : null,
decorationColor: color,
),
),
),
if (items.length > maxShown)
Text(
"+${items.length - maxShown} more",
style: style?.copyWith(color: theme.colorScheme.onSurfaceVariant),
),
];
return Wrap(
spacing: 8,
runSpacing: 2,
crossAxisAlignment: .center,
children: [
if (label case final label?)
Text(label, style: style?.copyWith(fontWeight: .bold)),
...items(removed, color: removedColor, struck: true),
...items(added, color: addedColor, struck: false),
...trailing,
],
);
}
}