import 'package:flutter/material.dart'; import '../theme/app_theme.dart'; /// Small uppercase label above a group, e.g. "OBVESTILA". class SectionHeader extends StatelessWidget { final String label; final Widget? trailing; const SectionHeader(this.label, {super.key, this.trailing}); @override Widget build(BuildContext context) { final c = Palette.current; return Padding( padding: const EdgeInsets.fromLTRB(0, 22, 0, 10), child: Row( children: [ Expanded(child: Text(label.toUpperCase(), style: AppTheme.kicker(c))), if (trailing != null) trailing!, ], ), ); } } /// Rounded group of rows with thin dividers between them. class GroupCard extends StatelessWidget { final List children; final bool indentDividers; const GroupCard({super.key, required this.children, this.indentDividers = true}); @override Widget build(BuildContext context) { final c = Palette.current; return DecoratedBox( decoration: BoxDecoration(borderRadius: BorderRadius.circular(AppTheme.radius), boxShadow: c.shadow), child: Material( color: c.card, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(AppTheme.radius), side: BorderSide(color: c.line2), ), clipBehavior: Clip.antiAlias, child: Column( children: [ for (int i = 0; i < children.length; i++) ...[ if (i > 0) Divider(height: 1, thickness: 1, indent: indentDividers ? 16 : 0, endIndent: indentDividers ? 16 : 0, color: c.line2), children[i], ], ], ), ), ); } } /// One settings row: icon, title (+ subtitle) on the left, current value and a /// chevron on the right. [trailing] replaces value + chevron (e.g. a switch). class SettingsTile extends StatelessWidget { final String title; final String? subtitle; final IconData? icon; final Color? iconColor; final Widget? leading; final String? value; final Color? valueColor; final Widget? valueLeading; final Widget? trailing; final VoidCallback? onTap; final bool mono; // value in the monospace font (IP addresses) final bool showChevron; final IconData chevron; final Color? titleColor; const SettingsTile({ super.key, required this.title, this.subtitle, this.icon, this.iconColor, this.leading, this.value, this.valueColor, this.valueLeading, this.trailing, this.onTap, this.mono = false, this.showChevron = true, this.chevron = Icons.chevron_right_rounded, this.titleColor, }); @override Widget build(BuildContext context) { final c = Palette.current; return InkWell( onTap: onTap, child: ConstrainedBox( constraints: const BoxConstraints(minHeight: 56), child: Padding( padding: const EdgeInsets.fromLTRB(16, 9, 12, 9), child: Row( children: [ if (leading != null) ...[leading!, const SizedBox(width: 14)] else if (icon != null) ...[Icon(icon, size: 21, color: iconColor ?? c.muted), const SizedBox(width: 14)], Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text(title, style: TextStyle(fontSize: 15.5, fontWeight: FontWeight.w500, color: titleColor ?? c.ink)), if (subtitle != null) Padding( padding: const EdgeInsets.only(top: 2), child: Text(subtitle!, style: TextStyle(fontSize: 12, color: c.muted)), ), ], ), ), if (trailing != null) trailing! else ...[ if (valueLeading != null) ...[valueLeading!, const SizedBox(width: 8)], if (value != null) ConstrainedBox( constraints: const BoxConstraints(maxWidth: 190), child: Text( value!, style: TextStyle( fontSize: mono ? 13 : 14, fontFamily: mono ? AppTheme.mono : null, color: valueColor ?? c.muted, fontFeatures: AppTheme.tnum, ), overflow: TextOverflow.ellipsis, ), ), if (onTap != null && showChevron) ...[ const SizedBox(width: 4), Icon(chevron, size: 20, color: c.faint), ], ], ], ), ), ), ); } } /// Settings row with a switch on the right; tapping the row toggles it. class SettingsSwitchTile extends StatelessWidget { final String title; final IconData? icon; final bool value; final ValueChanged onChanged; const SettingsSwitchTile({ super.key, required this.title, this.icon, required this.value, required this.onChanged, }); @override Widget build(BuildContext context) { return SettingsTile( title: title, icon: icon, onTap: () => onChanged(!value), trailing: SizedBox(height: 32, child: FittedBox(child: Switch(value: value, onChanged: onChanged))), ); } } /// Row of a picker sheet, with a check on the selected one. class SheetOption extends StatelessWidget { final String label; final String? subtitle; final Widget? leading; final bool selected; final VoidCallback onTap; final bool showDivider; const SheetOption({ super.key, required this.label, this.subtitle, this.leading, required this.selected, required this.onTap, this.showDivider = true, }); @override Widget build(BuildContext context) { final c = Palette.current; return InkWell( onTap: onTap, borderRadius: BorderRadius.circular(12), child: Container( constraints: const BoxConstraints(minHeight: 56), padding: const EdgeInsets.symmetric(vertical: 10), decoration: BoxDecoration( border: showDivider ? Border(top: BorderSide(color: c.line2)) : null, ), child: Row( children: [ if (leading != null) ...[leading!, const SizedBox(width: 12)], Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text(label, style: TextStyle(fontSize: 15.5, fontWeight: selected ? FontWeight.w600 : FontWeight.w500, color: c.ink)), if (subtitle != null) Padding( padding: const EdgeInsets.only(top: 3), child: Text(subtitle!, style: TextStyle(fontSize: 12, color: c.muted)), ), ], ), ), if (selected) Container( width: 24, height: 24, decoration: BoxDecoration(color: c.accent, shape: BoxShape.circle), child: Icon(Icons.check_rounded, size: 16, color: c.onAccent), ), ], ), ), ); } } /// Headline number with a small label above and an optional caption below. class StatTile extends StatelessWidget { final String label; final String value; final String? caption; const StatTile({super.key, required this.label, required this.value, this.caption}); @override Widget build(BuildContext context) { final c = Palette.current; return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(label, style: TextStyle(fontSize: 12, color: c.muted)), const SizedBox(height: 2), Text(value, style: TextStyle(fontSize: 28, fontWeight: FontWeight.w800, height: 1.15, color: c.ink, fontFeatures: AppTheme.tnum)), if (caption != null) Text(caption!, style: TextStyle(fontSize: 11.5, color: c.muted), maxLines: 1, overflow: TextOverflow.ellipsis), ], ); } } /// [StatTile]s two per row, each on its own card. class StatGrid extends StatelessWidget { final List tiles; const StatGrid({super.key, required this.tiles}); @override Widget build(BuildContext context) { final c = Palette.current; final rows = []; for (int i = 0; i < tiles.length; i += 2) { if (i > 0) rows.add(const SizedBox(height: 10)); rows.add(Row( children: [ for (final t in [tiles[i], if (i + 1 < tiles.length) tiles[i + 1]]) ...[ if (t != tiles[i]) const SizedBox(width: 10), Expanded( child: Container( padding: const EdgeInsets.fromLTRB(14, 12, 12, 12), decoration: BoxDecoration( color: c.card, borderRadius: BorderRadius.circular(AppTheme.radius), border: Border.all(color: c.line2), boxShadow: c.shadow, ), child: t, ), ), ], ], )); } return Column(children: rows); } }