249 lines
7.0 KiB
Dart
249 lines
7.0 KiB
Dart
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;
|
|
|
|
const SectionHeader(this.label, {super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(4, 20, 4, 8),
|
|
child: Text(
|
|
label.toUpperCase(),
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
letterSpacing: 1.4,
|
|
color: Surfaces.current.textSecondary,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Rounded group of rows with thin dividers between them.
|
|
class GroupCard extends StatelessWidget {
|
|
final List<Widget> children;
|
|
|
|
const GroupCard({super.key, required this.children});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final s = Surfaces.current;
|
|
return ClipRRect(
|
|
borderRadius: BorderRadius.circular(14),
|
|
child: Material(
|
|
color: s.card,
|
|
child: Column(
|
|
children: [
|
|
for (int i = 0; i < children.length; i++) ...[
|
|
if (i > 0) Divider(height: 1, thickness: 1, indent: 16, color: s.divider),
|
|
children[i],
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// One settings row: title (+ optional subtitle) on the left, current value and
|
|
/// a chevron on the right. Pass [trailing] to replace value + chevron (e.g. a Switch).
|
|
class SettingsTile extends StatelessWidget {
|
|
final String title;
|
|
final String? subtitle;
|
|
final Widget? leading;
|
|
final String? value;
|
|
final Widget? valueLeading;
|
|
final Widget? trailing;
|
|
final VoidCallback? onTap;
|
|
|
|
const SettingsTile({
|
|
super.key,
|
|
required this.title,
|
|
this.subtitle,
|
|
this.leading,
|
|
this.value,
|
|
this.valueLeading,
|
|
this.trailing,
|
|
this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final s = Surfaces.current;
|
|
return InkWell(
|
|
onTap: onTap,
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(minHeight: 52),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
|
child: Row(
|
|
children: [
|
|
if (leading != null) ...[leading!, const SizedBox(width: 12)],
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(title, style: TextStyle(fontSize: 15, color: s.textPrimary)),
|
|
if (subtitle != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 2),
|
|
child: Text(subtitle!, style: TextStyle(fontSize: 12, color: s.textSecondary)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (trailing != null)
|
|
trailing!
|
|
else ...[
|
|
if (valueLeading != null) ...[valueLeading!, const SizedBox(width: 8)],
|
|
if (value != null)
|
|
ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 170),
|
|
child: Text(
|
|
value!,
|
|
style: TextStyle(fontSize: 14, color: s.textSecondary),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
if (onTap != null) Icon(Icons.chevron_right, color: s.textSecondary),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Settings row with a switch on the right; tapping the row toggles it.
|
|
class SettingsSwitchTile extends StatelessWidget {
|
|
final String title;
|
|
final bool value;
|
|
final ValueChanged<bool> onChanged;
|
|
final Color activeColor;
|
|
|
|
const SettingsSwitchTile({
|
|
super.key,
|
|
required this.title,
|
|
required this.value,
|
|
required this.onChanged,
|
|
required this.activeColor,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SettingsTile(
|
|
title: title,
|
|
onTap: () => onChanged(!value),
|
|
trailing: SizedBox(
|
|
height: 32,
|
|
child: FittedBox(
|
|
child: Switch(
|
|
value: value,
|
|
onChanged: onChanged,
|
|
activeTrackColor: activeColor,
|
|
activeThumbColor: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Row used inside dark bottom-sheet pickers, with a check on the selected one.
|
|
class SheetOption extends StatelessWidget {
|
|
final String label;
|
|
final Widget? leading;
|
|
final bool selected;
|
|
final Color selectedColor;
|
|
final VoidCallback onTap;
|
|
|
|
const SheetOption({
|
|
super.key,
|
|
required this.label,
|
|
this.leading,
|
|
required this.selected,
|
|
required this.selectedColor,
|
|
required this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListTile(
|
|
onTap: onTap,
|
|
leading: leading,
|
|
title: Text(
|
|
label,
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontWeight: selected ? FontWeight.bold : FontWeight.normal,
|
|
),
|
|
),
|
|
trailing: selected ? Icon(Icons.check_rounded, color: selectedColor) : null,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 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 s = Surfaces.current;
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 12, 12, 12),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(label, style: TextStyle(fontSize: 12, color: s.textSecondary)),
|
|
const SizedBox(height: 2),
|
|
Text(value, style: TextStyle(fontSize: 26, fontWeight: FontWeight.bold, color: s.textPrimary)),
|
|
if (caption != null)
|
|
Text(caption!, style: TextStyle(fontSize: 11, color: s.textSecondary), maxLines: 1, overflow: TextOverflow.ellipsis),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Grid of [StatTile]s, two per row, on one card.
|
|
class StatGrid extends StatelessWidget {
|
|
final List<StatTile> tiles;
|
|
|
|
const StatGrid({super.key, required this.tiles});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final s = Surfaces.current;
|
|
final rows = <Widget>[];
|
|
for (int i = 0; i < tiles.length; i += 2) {
|
|
if (i > 0) rows.add(Divider(height: 1, thickness: 1, color: s.divider));
|
|
rows.add(IntrinsicHeight(
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Expanded(child: tiles[i]),
|
|
VerticalDivider(width: 1, thickness: 1, color: s.divider),
|
|
Expanded(child: i + 1 < tiles.length ? tiles[i + 1] : const SizedBox()),
|
|
],
|
|
),
|
|
));
|
|
}
|
|
return ClipRRect(
|
|
borderRadius: BorderRadius.circular(14),
|
|
child: ColoredBox(color: s.card, child: Column(children: rows)),
|
|
);
|
|
}
|
|
}
|