UI fixes and league

This commit is contained in:
Jan Pleterski
2026-11-28 12:22:02 +01:00
parent 2fc741a9f6
commit 258303deb8
118 changed files with 1439 additions and 537 deletions
+155 -51
View File
@@ -176,13 +176,19 @@ class SegmentItem {
const SegmentItem(this.label, [this.icon]);
}
/// Two or three equal segments in a card ("Statistika | Zgodovina").
/// Two or three equal segments in a card ("Statistika | Zgodovina"). The
/// selected pill hops over to a newly picked segment (a slide with a slight
/// overshoot). [trailing] sits at the end of the same bar, after a thin line
/// (e.g. a menu); [bare] leaves out the bar's own card, for several rows in
/// one card (see [SegmentedCard]).
class SegmentedTabs extends StatelessWidget {
final List<SegmentItem> items;
final int selected;
final ValueChanged<int> onSelect;
final double height;
final bool accentSelected; // selected segment filled with the accent
final Widget? trailing;
final bool bare;
const SegmentedTabs({
super.key,
@@ -191,62 +197,125 @@ class SegmentedTabs extends StatelessWidget {
required this.onSelect,
this.height = 44,
this.accentSelected = false,
this.trailing,
this.bare = false,
});
static const Duration _hop = Duration(milliseconds: 380);
// Slides past its target a little and settles back: a hop, not a fade
static const Curve _hopCurve = Cubic(0.3, 1.3, 0.5, 1);
static BoxDecoration track(Palette c) => BoxDecoration(
color: c.isDark ? c.card : c.tile,
borderRadius: BorderRadius.circular(14),
border: c.isDark ? Border.all(color: c.line) : null,
);
@override
Widget build(BuildContext context) {
final c = Palette.current;
final segments = LayoutBuilder(builder: (context, box) {
final w = box.maxWidth / items.length;
return Stack(
children: [
// The pill, under the labels
if (selected >= 0 && selected < items.length)
AnimatedPositioned(
duration: _hop,
curve: _hopCurve,
left: w * selected,
top: 0,
bottom: 0,
width: w,
child: AnimatedContainer(
duration: const Duration(milliseconds: 180),
decoration: BoxDecoration(
color: accentSelected ? c.accent : (c.isDark ? c.tile : c.card),
borderRadius: BorderRadius.circular(10),
boxShadow: !c.isDark ? c.shadow : null,
),
),
),
Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
for (int i = 0; i < items.length; i++)
Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => onSelect(i),
child: TweenAnimationBuilder<Color?>(
tween: ColorTween(end: _fg(c, i)),
duration: const Duration(milliseconds: 220),
builder: (context, fg, _) => Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (items[i].icon != null) ...[
Icon(items[i].icon, size: 16, color: fg),
const SizedBox(width: 8),
],
Flexible(
child: Text(
items[i].label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: fg),
),
),
],
),
),
),
),
],
),
],
);
});
final bar = trailing == null
? segments
: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(child: segments),
Container(width: 1, margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 6), color: c.isDark ? c.line : c.line2),
trailing!,
],
);
return Container(
height: height,
padding: bare ? EdgeInsets.zero : const EdgeInsets.all(4),
decoration: bare ? null : track(c),
child: bar,
);
}
Color _fg(Palette c, int i) => i != selected ? c.muted : (accentSelected ? c.onAccent : c.ink);
}
/// Several [SegmentedTabs] rows (built [bare]) in one card, a thin line
/// between them: "Statistika | Zgodovina" over its filters.
class SegmentedCard extends StatelessWidget {
final List<Widget> rows;
const SegmentedCard({super.key, required this.rows});
@override
Widget build(BuildContext context) {
final c = Palette.current;
return Container(
height: height,
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: c.isDark ? c.card : c.tile,
borderRadius: BorderRadius.circular(14),
border: c.isDark ? Border.all(color: c.line) : null,
),
child: Row(
// The selected pill fills the bar's height
crossAxisAlignment: CrossAxisAlignment.stretch,
decoration: SegmentedTabs.track(c),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
for (int i = 0; i < items.length; i++)
Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => onSelect(i),
child: AnimatedContainer(
duration: const Duration(milliseconds: 180),
curve: Curves.easeOut,
decoration: BoxDecoration(
color: i == selected ? (accentSelected ? c.accent : (c.isDark ? c.tile : c.card)) : Colors.transparent,
borderRadius: BorderRadius.circular(10),
boxShadow: i == selected && !c.isDark ? c.shadow : null,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (items[i].icon != null) ...[
Icon(items[i].icon, size: 16, color: _fg(c, i)),
const SizedBox(width: 8),
],
Flexible(
child: Text(
items[i].label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: _fg(c, i)),
),
),
],
),
),
),
),
for (int i = 0; i < rows.length; i++) ...[
if (i > 0) Container(height: 1, margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), color: c.isDark ? c.line : c.line2),
rows[i],
],
],
),
);
}
Color _fg(Palette c, int i) => i != selected ? c.muted : (accentSelected ? c.onAccent : c.ink);
}
/// Stadium chip: accent when selected ("Treningi", "Vse").
@@ -304,6 +373,7 @@ class AppCard extends StatelessWidget {
final double radius;
final Color? color;
final Color? borderColor;
final double borderWidth;
final bool dashed;
const AppCard({
@@ -315,6 +385,7 @@ class AppCard extends StatelessWidget {
this.radius = AppTheme.radius,
this.color,
this.borderColor,
this.borderWidth = 1,
this.dashed = false,
});
@@ -323,7 +394,7 @@ class AppCard extends StatelessWidget {
final c = Palette.current;
final shape = RoundedRectangleBorder(
borderRadius: BorderRadius.circular(radius),
side: dashed ? BorderSide.none : BorderSide(color: borderColor ?? (c.isDark ? c.line2 : c.line2)),
side: dashed ? BorderSide.none : BorderSide(color: borderColor ?? (c.isDark ? c.line2 : c.line2), width: borderWidth),
);
Widget content = Padding(padding: padding, child: child);
if (onTap != null || onLongPress != null) {
@@ -447,7 +518,8 @@ class SoftButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final c = Palette.current;
final fg = destructive ? c.red : c.ink;
// Without an action it is visibly off, so it never looks like it does nothing
final fg = (destructive ? c.red : c.ink).withValues(alpha: onTap == null ? 0.35 : 1);
return Material(
color: destructive ? c.redSoft : c.tile,
borderRadius: BorderRadius.circular(12),
@@ -486,6 +558,7 @@ class ScoreTile extends StatelessWidget {
final GestureTapDownCallback? onTapDown;
final VoidCallback? onTapEnd;
final bool outlined;
final double radius;
const ScoreTile({
super.key,
@@ -498,6 +571,7 @@ class ScoreTile extends StatelessWidget {
this.onTapDown,
this.onTapEnd,
this.outlined = false,
this.radius = 14,
});
@override
@@ -515,16 +589,19 @@ class ScoreTile extends StatelessWidget {
height: height,
decoration: BoxDecoration(
color: fill,
borderRadius: BorderRadius.circular(14),
borderRadius: BorderRadius.circular(radius),
border: outlined ? Border.all(color: c.ink, width: 2) : null,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (top != null)
Text(top!,
style: TextStyle(
fontSize: 10, fontWeight: FontWeight.w600, color: fg.withValues(alpha: 0.7), fontFeatures: AppTheme.tnum)),
FittedBox(
fit: BoxFit.scaleDown,
child: Text(top!,
style: TextStyle(
fontSize: 10, fontWeight: FontWeight.w600, color: fg.withValues(alpha: 0.7), fontFeatures: AppTheme.tnum)),
),
FittedBox(
fit: BoxFit.scaleDown,
child: Text(value,
@@ -538,6 +615,33 @@ class ScoreTile extends StatelessWidget {
}
}
/// A centred row of equal tiles. Each is as wide as if there were at least
/// [minSlots], so one or two tiles don't stretch across the whole width.
class TileRow extends StatelessWidget {
final List<Widget> children;
final double gap;
final int minSlots;
const TileRow({super.key, required this.children, this.gap = 10, this.minSlots = 6});
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, box) {
final slots = children.length < minSlots ? minSlots : children.length;
final w = (box.maxWidth - gap * (slots - 1)) / slots;
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
for (int i = 0; i < children.length; i++) ...[
if (i > 0) SizedBox(width: gap),
SizedBox(width: w, child: children[i]),
],
],
);
});
}
}
/// Small coloured label: "TRENING", "TEKMOVANJE", "V ŽIVO".
class StatusChip extends StatelessWidget {
final String label;