google preperation 1

This commit is contained in:
2026-10-26 20:48:16 +01:00
parent 9a65ff7ad4
commit 3b50cb0fe9
47 changed files with 4969 additions and 4580 deletions
+73
View File
@@ -0,0 +1,73 @@
import 'package:flutter/material.dart';
import '../theme/app_theme.dart';
class BarTab {
final String label;
final IconData icon;
const BarTab(this.label, this.icon);
}
/// Tab strip that continues the dark app bar (Koledar/Stiki, Knjiga filters).
/// The selected tab is a white pill; [trailing] sits at the right end.
class BarTabs extends StatelessWidget {
final List<BarTab> tabs;
final int selected;
final ValueChanged<int> onSelect;
final Widget? trailing;
const BarTabs({
super.key,
required this.tabs,
required this.selected,
required this.onSelect,
this.trailing,
});
@override
Widget build(BuildContext context) {
return Container(
color: AppTheme.bar,
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
child: Row(
children: [
for (int i = 0; i < tabs.length; i++) ...[
if (i > 0) const SizedBox(width: 6),
Expanded(child: _tab(tabs[i], i == selected, () => onSelect(i))),
],
if (trailing != null) trailing!,
],
),
);
}
Widget _tab(BarTab tab, bool active, VoidCallback onTap) {
final color = active ? Colors.black : Colors.grey[400];
return GestureDetector(
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
decoration: BoxDecoration(
color: active ? Colors.white : Colors.transparent,
borderRadius: BorderRadius.circular(10),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Icon(tab.icon, color: color, size: 18),
const SizedBox(width: 6),
Flexible(
child: Text(
tab.label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: color),
),
),
],
),
),
);
}
}
+29 -34
View File
@@ -1,48 +1,43 @@
import 'package:flutter/material.dart';
import '../utils/translations.dart';
import '../theme/app_theme.dart';
class BottomNavBar extends StatelessWidget {
final int selectedIndex;
final Function(int) onItemTapped;
final String selectedLanguage;
final ValueChanged<int> onItemTapped;
final List<BottomNavigationBarItem> items;
const BottomNavBar({
super.key,
required this.selectedIndex,
required this.onItemTapped,
required this.selectedLanguage,
required this.items,
});
String _t(String key) {
return AppTranslations.translate(key, selectedLanguage);
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: SizedBox(
height: 80,
child: BottomNavigationBar(
backgroundColor: Colors.grey[900],
currentIndex: selectedIndex,
onTap: onItemTapped,
showSelectedLabels: true,
showUnselectedLabels: true,
type: BottomNavigationBarType.fixed,
selectedFontSize: 12,
unselectedFontSize: 12,
selectedItemColor: Colors.white,
unselectedItemColor: Colors.white70,
items: [
BottomNavigationBarItem(icon: const Icon(Icons.book), label: _t("Book")),
BottomNavigationBarItem(icon: const Icon(Icons.my_location), label: _t("Shooting")),
BottomNavigationBarItem(icon: const Icon(Icons.camera_alt), label: _t("Camera")),
BottomNavigationBarItem(icon: const Icon(Icons.calendar_today), label: _t("Calendar")),
BottomNavigationBarItem(icon: const Icon(Icons.settings), label: _t("Settings")),
],
Widget build(BuildContext context) {
// Paint the gesture-bar strip below the nav too (edge-to-edge since targetSdk 35),
// otherwise the target background color shows through as a thin line.
return ColoredBox(
color: AppTheme.bar,
child: SafeArea(
top: false,
child: SizedBox(
height: 80,
child: BottomNavigationBar(
backgroundColor: AppTheme.bar,
currentIndex: selectedIndex,
onTap: onItemTapped,
showSelectedLabels: true,
showUnselectedLabels: true,
type: BottomNavigationBarType.fixed,
selectedFontSize: 12,
unselectedFontSize: 12,
selectedItemColor: Colors.white,
unselectedItemColor: Colors.white70,
items: items,
),
),
),
),
);
}
);
}
}
+236
View File
@@ -0,0 +1,236 @@
import 'package:flutter/material.dart';
/// Bottom sheet used by every menu on the camera stream: the live image stays
/// visible and undimmed above it, so changes can be judged immediately.
Future<T?> showCameraSheet<T>(BuildContext context,
{required WidgetBuilder builder}) {
return showModalBottomSheet<T>(
context: context,
barrierColor: Colors.transparent,
backgroundColor: Colors.grey[900],
isScrollControlled:
true, // tall content (timer) may use more than half the screen
builder: (sheet) => SafeArea(
child: ConstrainedBox(
constraints:
BoxConstraints(maxHeight: MediaQuery.sizeOf(sheet).height * 0.75),
child: SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(20, 0, 20, 16),
child: builder(sheet),
),
),
),
);
}
/// Title (+ optional subtitle) on the left, optional action on the right.
class CameraSheetHeader extends StatelessWidget {
final String title;
final String? subtitle;
final IconData? icon;
final Color? iconColor;
final Widget? trailing;
const CameraSheetHeader({
super.key,
required this.title,
this.subtitle,
this.icon,
this.iconColor,
this.trailing,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(bottom: 14),
child: Row(
children: [
if (icon != null) ...[
Icon(icon, color: iconColor ?? Colors.white, size: 22),
const SizedBox(width: 8),
],
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title,
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold)),
if (subtitle != null)
Text(subtitle!,
style:
const TextStyle(color: Colors.white54, fontSize: 12)),
],
),
),
if (trailing != null) trailing!,
],
),
);
}
}
/// Icon, label, slider and current value in one row.
class SheetSlider extends StatelessWidget {
final IconData icon;
final String label;
final String valueText;
final double value;
final double min;
final double max;
final Color accent;
final ValueChanged<double> onChanged;
const SheetSlider({
required this.icon,
required this.label,
required this.valueText,
required this.value,
required this.min,
required this.max,
required this.accent,
required this.onChanged,
});
@override
Widget build(BuildContext context) {
return Row(
children: [
Icon(icon, color: Colors.white54, size: 20),
const SizedBox(width: 8),
SizedBox(
width: 72,
child: Text(label,
style: const TextStyle(color: Colors.white, fontSize: 13)),
),
Expanded(
child: Slider(
value: value.clamp(min, max),
min: min,
max: max,
activeColor: accent,
inactiveColor: Colors.white24,
onChanged: onChanged,
),
),
SizedBox(
width: 46,
child: Text(
valueText,
textAlign: TextAlign.right,
style: const TextStyle(
color: Colors.white70,
fontSize: 13,
fontFeatures: [FontFeature.tabularFigures()]),
),
),
],
);
}
}
/// Wide button that shows an on/off state with the accent color.
class SheetToggle extends StatelessWidget {
final IconData icon;
final String label;
final bool active;
final Color accent;
final VoidCallback onTap;
const SheetToggle({
required this.icon,
required this.label,
required this.active,
required this.accent,
required this.onTap,
});
@override
Widget build(BuildContext context) {
return Material(
color: active
? accent.withValues(alpha: 0.18)
: Colors.white.withValues(alpha: 0.06),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side:
BorderSide(color: active ? accent : Colors.transparent, width: 1.5),
),
child: InkWell(
borderRadius: BorderRadius.circular(12),
onTap: onTap,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, size: 18, color: active ? accent : Colors.white70),
const SizedBox(width: 6),
Flexible(
child: Text(
label,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 13,
color: active ? Colors.white : Colors.white70),
),
),
],
),
),
),
);
}
}
/// Big number with − / + buttons, used for the bullet count.
class SheetStepper extends StatelessWidget {
final int value;
final int min;
final int max;
final Color accent;
final ValueChanged<int> onChanged;
const SheetStepper({
super.key,
required this.value,
required this.min,
required this.max,
required this.accent,
required this.onChanged,
});
@override
Widget build(BuildContext context) {
Widget button(IconData icon, bool enabled, int next) => IconButton(
onPressed: enabled ? () => onChanged(next) : null,
icon: Icon(icon, color: Colors.white, size: 28),
style: IconButton.styleFrom(
backgroundColor:
Colors.white.withValues(alpha: enabled ? 0.12 : 0.04),
shape: const CircleBorder(),
minimumSize: const Size(56, 56),
),
);
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
button(Icons.remove, value > min, value - 1),
SizedBox(
width: 120,
child: Text(
'$value',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 56, fontWeight: FontWeight.bold, color: accent),
),
),
button(Icons.add, value < max, value + 1),
],
);
}
}
+258
View File
@@ -0,0 +1,258 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'camera_sheet.dart';
enum ImageFilterType { none, greyscale, invert, highContrast }
/// Live-image adjustments for one camera stream. Saved per camera, because
/// lighting differs from lane to lane.
class ImageAdjustments {
final ImageFilterType filter;
final double brightness; // -1 … 1
final double contrast; // 0.5 … 2
final int quarterTurns; // 0–3, for cameras mounted sideways
const ImageAdjustments({
this.filter = ImageFilterType.none,
this.brightness = 0,
this.contrast = 1,
this.quarterTurns = 0,
});
ImageAdjustments copyWith({
ImageFilterType? filter,
double? brightness,
double? contrast,
int? quarterTurns,
}) {
return ImageAdjustments(
filter: filter ?? this.filter,
brightness: brightness ?? this.brightness,
contrast: contrast ?? this.contrast,
quarterTurns: quarterTurns ?? this.quarterTurns,
);
}
/// Keeps rotation, resets the picture itself.
ImageAdjustments resetPicture() =>
copyWith(filter: ImageFilterType.none, brightness: 0, contrast: 1);
// Older versions stored one global setting; use it until a camera has its own
static Future<ImageAdjustments> load(String camera) async {
final p = await SharedPreferences.getInstance();
final filter =
p.getInt('filter_cam$camera') ?? p.getInt('selectedFilter') ?? 0;
return ImageAdjustments(
filter: ImageFilterType
.values[filter.clamp(0, ImageFilterType.values.length - 1)],
brightness: p.getDouble('brightness_cam$camera') ??
p.getDouble('brightness') ??
0,
contrast:
p.getDouble('contrast_cam$camera') ?? p.getDouble('contrast') ?? 1,
quarterTurns: p.getInt('rotation_cam$camera') ?? 0,
);
}
Future<void> save(String camera) async {
final p = await SharedPreferences.getInstance();
await p.setInt('filter_cam$camera', filter.index);
await p.setDouble('brightness_cam$camera', brightness);
await p.setDouble('contrast_cam$camera', contrast);
await p.setInt('rotation_cam$camera', quarterTurns);
}
/// Filter first, then contrast around mid-grey and brightness on top.
ColorFilter get colorFilter {
const lum = [0.2126, 0.7152, 0.0722];
final List<double> base = switch (filter) {
ImageFilterType.greyscale || ImageFilterType.highContrast => [
...lum, 0, 0, //
...lum, 0, 0,
...lum, 0, 0,
0, 0, 0, 1, 0,
],
ImageFilterType.invert => [
-1, 0, 0, 0, 255, //
0, -1, 0, 0, 255,
0, 0, -1, 0, 255,
0, 0, 0, 1, 0,
],
ImageFilterType.none => [
1, 0, 0, 0, 0, //
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0,
],
};
// High contrast makes dark holes stand out on a light target
final c = contrast * (filter == ImageFilterType.highContrast ? 2.2 : 1);
final m = [...base];
for (final row in [0, 5, 10]) {
for (int i = 0; i < 4; i++) {
m[row + i] *= c;
}
m[row + 4] = m[row + 4] * c + 128 * (1 - c) + brightness * 255;
}
return ColorFilter.matrix(m);
}
}
/// Bottom sheet that leaves the live image visible, so every change is seen immediately.
Future<void> showImageSettingsSheet(
BuildContext context, {
required ImageAdjustments initial,
required String settingsId,
required String cameraLabel,
required Color accent,
required String Function(String) t,
required ValueChanged<ImageAdjustments> onChanged,
}) {
var value = initial;
return showCameraSheet(
context,
builder: (sheet) => StatefulBuilder(
builder: (context, setSheetState) {
void update(ImageAdjustments next) {
setSheetState(() => value = next);
onChanged(next);
next.save(settingsId);
}
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CameraSheetHeader(
title: t('Image Settings'),
subtitle: '$cameraLabel · ${t('Saved for this camera')}',
trailing: TextButton.icon(
style: TextButton.styleFrom(foregroundColor: Colors.white70),
icon: const Icon(Icons.restart_alt_rounded, size: 18),
label: Text(t('Reset')),
onPressed: () => update(value.resetPicture()),
),
),
Row(
children: [
for (final (f, icon, label) in [
(ImageFilterType.none, Icons.image_outlined, 'None'),
(
ImageFilterType.greyscale,
Icons.filter_b_and_w_rounded,
'Greyscale'
),
(
ImageFilterType.highContrast,
Icons.contrast_rounded,
'High contrast'
),
(
ImageFilterType.invert,
Icons.invert_colors_rounded,
'Invert'
),
]) ...[
if (f != ImageFilterType.none) const SizedBox(width: 8),
Expanded(
child: _FilterTile(
icon: icon,
label: t(label),
selected: value.filter == f,
accent: accent,
onTap: () => update(value.copyWith(filter: f)),
),
),
],
],
),
const SizedBox(height: 14),
SheetSlider(
icon: Icons.brightness_6_rounded,
label: t('Brightness'),
valueText:
'${value.brightness >= 0 ? '+' : ''}${(value.brightness * 100).round()}',
value: value.brightness,
min: -1,
max: 1,
accent: accent,
onChanged: (v) => update(value.copyWith(brightness: v)),
),
SheetSlider(
icon: Icons.tonality_rounded,
label: t('Contrast'),
valueText: '${(value.contrast * 100).round()} %',
value: value.contrast,
min: 0.5,
max: 2,
accent: accent,
onChanged: (v) => update(value.copyWith(contrast: v)),
),
const SizedBox(height: 8),
SheetToggle(
icon: Icons.rotate_90_degrees_cw_rounded,
label: '${t('Rotate')} · ${value.quarterTurns * 90}°',
active: value.quarterTurns != 0,
accent: accent,
onTap: () => update(
value.copyWith(quarterTurns: (value.quarterTurns + 1) % 4)),
),
],
);
},
),
);
}
class _FilterTile extends StatelessWidget {
final IconData icon;
final String label;
final bool selected;
final Color accent;
final VoidCallback onTap;
const _FilterTile({
required this.icon,
required this.label,
required this.selected,
required this.accent,
required this.onTap,
});
@override
Widget build(BuildContext context) {
return Material(
color: selected
? accent.withValues(alpha: 0.18)
: Colors.white.withValues(alpha: 0.06),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
side:
BorderSide(color: selected ? accent : Colors.transparent, width: 2),
),
child: InkWell(
borderRadius: BorderRadius.circular(14),
onTap: onTap,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 4),
child: Column(
children: [
Icon(icon, color: selected ? accent : Colors.white70, size: 26),
const SizedBox(height: 4),
Text(
label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: selected ? Colors.white : Colors.white70,
),
),
],
),
),
),
);
}
}
-36
View File
@@ -1,36 +0,0 @@
import 'package:flutter/material.dart';
class InputField extends StatelessWidget {
final String hintText;
final IconData icon;
final bool obscureText;
final TextEditingController controller;
const InputField({
super.key,
required this.hintText,
required this.icon,
this.obscureText = false,
required this.controller,
});
@override
Widget build(BuildContext context) {
return TextField(
controller: controller,
obscureText: obscureText,
style: const TextStyle(color: Colors.grey), // Text inside input field is gray
decoration: InputDecoration(
prefixIcon: Icon(icon, color: Colors.grey), // Icons inside input field are gray
hintText: hintText,
hintStyle: const TextStyle(color: Colors.grey), // Placeholder text is gray
filled: true,
fillColor: Colors.grey[300], // Light gray background for inputs
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none, // No border
),
),
);
}
}
+174
View File
@@ -0,0 +1,174 @@
import 'package:flutter/material.dart';
class ChartPoint {
final String label; // shown in the tooltip and under the first/last point
final double value;
const ChartPoint(this.label, this.value);
}
/// Single-series line chart: 2px line, 8px points, three faint gridlines.
/// Tap (or drag) to show the nearest point's label and value.
class ProgressChart extends StatefulWidget {
final List<ChartPoint> points;
final Color color;
final Color textColor;
final Color gridColor;
const ProgressChart({
super.key,
required this.points,
required this.color,
required this.textColor,
required this.gridColor,
});
@override
State<ProgressChart> createState() => _ProgressChartState();
}
class _ProgressChartState extends State<ProgressChart> {
int? _selected;
void _select(Offset position, Size size) {
final n = widget.points.length;
if (n == 0) return;
final plotWidth = size.width - _ChartPainter.leftAxis - _ChartPainter.pad * 2;
final x = (position.dx - _ChartPainter.leftAxis - _ChartPainter.pad) / plotWidth;
setState(() => _selected = (x * (n - 1)).round().clamp(0, n - 1));
}
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
final size = Size(constraints.maxWidth, 170);
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTapDown: (d) => _select(d.localPosition, size),
onHorizontalDragUpdate: (d) => _select(d.localPosition, size),
child: CustomPaint(
size: size,
painter: _ChartPainter(
points: widget.points,
color: widget.color,
textColor: widget.textColor,
gridColor: widget.gridColor,
selected: _selected,
),
),
);
},
);
}
}
class _ChartPainter extends CustomPainter {
static const double leftAxis = 32; // room for y labels
static const double pad = 10; // keeps end points inside the plot
static const double top = 34; // room for the tooltip
static const double bottom = 20; // room for x labels
final List<ChartPoint> points;
final Color color;
final Color textColor;
final Color gridColor;
final int? selected;
_ChartPainter({
required this.points,
required this.color,
required this.textColor,
required this.gridColor,
required this.selected,
});
@override
void paint(Canvas canvas, Size size) {
if (points.isEmpty) return;
final values = points.map((p) => p.value);
var minV = values.reduce((a, b) => a < b ? a : b);
var maxV = values.reduce((a, b) => a > b ? a : b);
if (maxV - minV < 1) {
minV -= 0.5;
maxV += 0.5;
}
final plot = Rect.fromLTRB(leftAxis + pad, top, size.width - pad, size.height - bottom);
Offset at(int i) => Offset(
points.length == 1 ? plot.center.dx : plot.left + plot.width * i / (points.length - 1),
plot.bottom - plot.height * (points[i].value - minV) / (maxV - minV),
);
// Gridlines + y labels (min, mid, max)
final grid = Paint()
..color = gridColor
..strokeWidth = 1;
for (final f in [0.0, 0.5, 1.0]) {
final y = plot.bottom - plot.height * f;
canvas.drawLine(Offset(leftAxis, y), Offset(size.width, y), grid);
_text(canvas, (minV + (maxV - minV) * f).toStringAsFixed(1), Offset(0, y - 7), 11, textColor);
}
// x labels: first and last only
_text(canvas, points.first.label, Offset(plot.left - pad, plot.bottom + 5), 11, textColor);
if (points.length > 1) {
_text(canvas, points.last.label, Offset(plot.right, plot.bottom + 5), 11, textColor, alignRight: true);
}
// Line
final path = Path()..moveTo(at(0).dx, at(0).dy);
for (int i = 1; i < points.length; i++) {
path.lineTo(at(i).dx, at(i).dy);
}
canvas.drawPath(
path,
Paint()
..color = color
..strokeWidth = 2
..style = PaintingStyle.stroke
..strokeJoin = StrokeJoin.round,
);
// Points with a surface ring so they read on top of the line
for (int i = 0; i < points.length; i++) {
final isSel = i == selected;
canvas.drawCircle(at(i), isSel ? 7 : 5, Paint()..color = Colors.white);
canvas.drawCircle(at(i), isSel ? 5.5 : 4, Paint()..color = color);
}
// Tooltip for the selected point
if (selected != null) {
final p = at(selected!);
canvas.drawLine(Offset(p.dx, plot.top), Offset(p.dx, plot.bottom), grid);
final label = '${points[selected!].label} ${points[selected!].value.toStringAsFixed(2)}';
final tp = _layout(label, 12, Colors.white, bold: true);
final w = tp.width + 16;
final left = (p.dx - w / 2).clamp(0.0, size.width - w);
canvas.drawRRect(
RRect.fromRectAndRadius(Rect.fromLTWH(left, 2, w, 24), const Radius.circular(6)),
Paint()..color = Colors.grey[900]!,
);
tp.paint(canvas, Offset(left + 8, 2 + (24 - tp.height) / 2));
}
}
TextPainter _layout(String text, double size, Color color, {bool bold = false}) {
return TextPainter(
text: TextSpan(
text: text,
style: TextStyle(fontSize: size, color: color, fontWeight: bold ? FontWeight.w600 : FontWeight.normal),
),
textDirection: TextDirection.ltr,
)..layout();
}
void _text(Canvas canvas, String text, Offset at, double size, Color color, {bool alignRight = false}) {
final tp = _layout(text, size, color);
tp.paint(canvas, alignRight ? at.translate(-tp.width, 0) : at);
}
@override
bool shouldRepaint(_ChartPainter old) =>
old.points != points || old.selected != selected || old.color != color || old.textColor != textColor;
}
+248
View File
@@ -0,0 +1,248 @@
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)),
);
}
}
+78
View File
@@ -0,0 +1,78 @@
import 'package:flutter/material.dart';
import '../services/app_settings.dart';
/// Dark dialog with one text field. Returns the trimmed text, or null if cancelled.
/// [onReset] adds a secondary button ([resetLabel], default "Reset to Default") that closes the dialog.
Future<String?> showTextPrompt(
BuildContext context, {
required String title,
String? message,
String initial = '',
String? hint,
TextInputType keyboardType = TextInputType.text,
String? confirmLabel,
String? resetLabel,
VoidCallback? onReset,
}) {
final s = AppSettings.instance;
final controller = TextEditingController(text: initial);
return showDialog<String>(
context: context,
builder: (dialog) => AlertDialog(
title: Text(title),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (message != null) ...[
Text(message),
const SizedBox(height: 16),
],
TextField(
controller: controller,
autofocus: true,
keyboardType: keyboardType,
autocorrect: false,
style: const TextStyle(color: Colors.white),
cursorColor: s.bulletColor,
decoration: InputDecoration(
hintText: hint,
hintStyle: const TextStyle(color: Colors.white38),
filled: true,
fillColor: Colors.white10,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: s.bulletColor),
),
),
onSubmitted: (v) => Navigator.pop(dialog, v.trim()),
),
],
),
actions: [
if (onReset != null)
TextButton(
onPressed: () {
onReset();
Navigator.pop(dialog);
},
child: Text(resetLabel ?? s.t('Reset to Default'), style: const TextStyle(color: Colors.white54)),
),
TextButton(
onPressed: () => Navigator.pop(dialog),
child: Text(s.t('Cancel'), style: const TextStyle(color: Colors.white70)),
),
FilledButton(
style: FilledButton.styleFrom(backgroundColor: s.bulletColor),
onPressed: () => Navigator.pop(dialog, controller.text.trim()),
child: Text(confirmLabel ?? s.t('Save')),
),
],
),
);
}