UI fixes and league
This commit is contained in:
+86
-105
@@ -6,7 +6,6 @@ import '../services/app_settings.dart';
|
||||
import '../services/target_repository.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import '../utils/format.dart';
|
||||
import '../widgets/bar_tabs.dart';
|
||||
import '../widgets/ui.dart';
|
||||
import '../widgets/help_sheet.dart';
|
||||
import '../widgets/progress_chart.dart';
|
||||
@@ -289,8 +288,7 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
|
||||
if (_view == _View.history) {
|
||||
return Column(children: [
|
||||
_buildTabs(),
|
||||
_buildHistoryBar(),
|
||||
_buildTabs(filters: _buildHistoryBar()),
|
||||
Expanded(child: _buildHistoryScreen()),
|
||||
]);
|
||||
}
|
||||
@@ -313,8 +311,7 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
_buildTabs(),
|
||||
_buildStatsBar(_formatCounts(typed.where(_inPeriod).toList()), shots),
|
||||
_buildTabs(filters: _buildStatsBar(_formatCounts(typed.where(_inPeriod).toList()), shots)),
|
||||
Expanded(
|
||||
child: _years.isEmpty
|
||||
? _centered(_buildEmpty())
|
||||
@@ -432,8 +429,8 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
);
|
||||
}
|
||||
|
||||
// Title, then the two screens
|
||||
Widget _buildTabs() {
|
||||
// Title, then one card: the two screens over that screen's filters
|
||||
Widget _buildTabs({Widget? filters}) {
|
||||
final s = AppSettings.instance;
|
||||
return Column(
|
||||
children: [
|
||||
@@ -441,13 +438,21 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
title: s.t('Book'),
|
||||
action: CircleButton(icon: Icons.info_outline_rounded, tooltip: s.t('Help'), onTap: () => showBookHelp(context)),
|
||||
),
|
||||
BarTabs(
|
||||
tabs: [
|
||||
BarTab(s.t('Statistics'), Icons.bar_chart_rounded),
|
||||
BarTab(s.t('History'), Icons.history_rounded),
|
||||
],
|
||||
selected: _view.index,
|
||||
onSelect: (i) => _change(() => _view = _View.values[i]),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(AppTheme.edge, 0, AppTheme.edge, 12),
|
||||
child: SegmentedCard(rows: [
|
||||
SegmentedTabs(
|
||||
bare: true,
|
||||
height: 40,
|
||||
items: [
|
||||
SegmentItem(s.t('Statistics'), Icons.bar_chart_rounded),
|
||||
SegmentItem(s.t('History'), Icons.history_rounded),
|
||||
],
|
||||
selected: _view.index,
|
||||
onSelect: (i) => _change(() => _view = _View.values[i]),
|
||||
),
|
||||
if (filters != null) filters,
|
||||
]),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -456,33 +461,19 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
// Zgodovina: which sessions to list
|
||||
Widget _buildHistoryBar() {
|
||||
final s = AppSettings.instance;
|
||||
final labels = {
|
||||
_HistoryFilter.all: s.t('All'),
|
||||
_HistoryFilter.training: s.t('Trainings'),
|
||||
_HistoryFilter.tournament: s.t('Tournaments'),
|
||||
};
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(AppTheme.edge, 0, AppTheme.edge, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
for (final f in _HistoryFilter.values) ...[
|
||||
if (f.index > 0) const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: ChoicePill(
|
||||
label: labels[f]!,
|
||||
selected: f == _historyFilter,
|
||||
onTap: () => _change(() => _historyFilter = f),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
return SegmentedTabs(
|
||||
bare: true,
|
||||
height: 36,
|
||||
items: [SegmentItem(s.t('All')), SegmentItem(s.t('Trainings')), SegmentItem(s.t('Tournaments'))],
|
||||
selected: _historyFilter.index,
|
||||
onSelect: (i) => _change(() => _historyFilter = _HistoryFilter.values[i]),
|
||||
);
|
||||
}
|
||||
|
||||
// Statistika: trainings or tournaments, then the shots-per-target format as
|
||||
// one chip with a menu. Shots are 1–5 (the capture limit); older saves above
|
||||
// 5 keep their own entry. Formats with no targets yet can't be picked.
|
||||
// Statistika: trainings or tournaments, and at the end of the same bar the
|
||||
// shots-per-target format as a menu. Shots are 1–5 (the capture limit);
|
||||
// older saves above 5 keep their own entry. Formats with no targets yet
|
||||
// can't be picked.
|
||||
Widget _buildStatsBar(Map<int, int> counts, int? selected) {
|
||||
final s = AppSettings.instance;
|
||||
final c = Palette.current;
|
||||
@@ -491,78 +482,68 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
...counts.keys,
|
||||
}.toList()
|
||||
..sort((a, b) => b.compareTo(a));
|
||||
Widget kind(_Filter f, String label) => ChoicePill(
|
||||
label: s.t(label),
|
||||
selected: f == _filter,
|
||||
onTap: () => _change(() {
|
||||
_filter = f;
|
||||
_shots = null;
|
||||
_chartAt = null;
|
||||
}),
|
||||
);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(AppTheme.edge, 0, AppTheme.edge, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: kind(_Filter.training, 'Trainings')),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(child: kind(_Filter.tournament, 'Tournaments')),
|
||||
const SizedBox(width: 6),
|
||||
PopupMenuButton<int>(
|
||||
tooltip: s.t('Shots per target'),
|
||||
initialValue: selected,
|
||||
position: PopupMenuPosition.under,
|
||||
offset: const Offset(0, 6),
|
||||
color: c.isDark ? c.card2 : c.card,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
side: BorderSide(color: c.line),
|
||||
),
|
||||
onSelected: (n) => _change(() => _shots = n),
|
||||
itemBuilder: (_) => [
|
||||
for (final n in sorted)
|
||||
PopupMenuItem<int>(
|
||||
value: n,
|
||||
enabled: (counts[n] ?? 0) > 0,
|
||||
height: 44,
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 22,
|
||||
child: n == selected ? Icon(Icons.check_rounded, size: 18, color: c.accent) : null,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(shotCount(n),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: n == selected ? FontWeight.w700 : FontWeight.w500,
|
||||
color: (counts[n] ?? 0) > 0 ? c.ink : c.faint)),
|
||||
const SizedBox(width: 16),
|
||||
const Spacer(),
|
||||
Text(targetCount(counts[n] ?? 0),
|
||||
style: TextStyle(fontSize: 12, color: c.muted, fontFeatures: AppTheme.tnum)),
|
||||
],
|
||||
),
|
||||
final shotsMenu = PopupMenuButton<int>(
|
||||
tooltip: s.t('Shots per target'),
|
||||
initialValue: selected,
|
||||
position: PopupMenuPosition.under,
|
||||
offset: const Offset(0, 6),
|
||||
color: c.isDark ? c.card2 : c.card,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
side: BorderSide(color: c.line),
|
||||
),
|
||||
onSelected: (n) => _change(() => _shots = n),
|
||||
itemBuilder: (_) => [
|
||||
for (final n in sorted)
|
||||
PopupMenuItem<int>(
|
||||
value: n,
|
||||
enabled: (counts[n] ?? 0) > 0,
|
||||
height: 44,
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 22,
|
||||
child: n == selected ? Icon(Icons.check_rounded, size: 18, color: c.accent) : null,
|
||||
),
|
||||
],
|
||||
child: Container(
|
||||
height: 32,
|
||||
padding: const EdgeInsets.only(left: 12, right: 6),
|
||||
decoration: BoxDecoration(color: c.tile, borderRadius: BorderRadius.circular(16)),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(selected == null ? '–' : shotCount(selected),
|
||||
style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: c.ink2)),
|
||||
Icon(Icons.expand_more_rounded, size: 18, color: c.muted),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(shotCount(n),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: n == selected ? FontWeight.w700 : FontWeight.w500,
|
||||
color: (counts[n] ?? 0) > 0 ? c.ink : c.faint)),
|
||||
const SizedBox(width: 16),
|
||||
const Spacer(),
|
||||
Text(targetCount(counts[n] ?? 0),
|
||||
style: TextStyle(fontSize: 12, color: c.muted, fontFeatures: AppTheme.tnum)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 8, right: 2),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(selected == null ? '–' : shotCount(selected),
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: c.ink)),
|
||||
Icon(Icons.expand_more_rounded, size: 18, color: c.muted),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
return SegmentedTabs(
|
||||
bare: true,
|
||||
height: 36,
|
||||
items: [SegmentItem(s.t('Trainings')), SegmentItem(s.t('Tournaments'))],
|
||||
selected: _filter.index,
|
||||
onSelect: (i) => _change(() {
|
||||
_filter = _Filter.values[i];
|
||||
_shots = null;
|
||||
_chartAt = null;
|
||||
}),
|
||||
trailing: shotsMenu,
|
||||
);
|
||||
}
|
||||
|
||||
// Monday–Sunday week of [date], cut to its month: "6.–12. 10.", "27.–31. 10."
|
||||
|
||||
@@ -10,6 +10,7 @@ import '../services/google_calendar_service.dart';
|
||||
import '../services/notification_service.dart';
|
||||
import '../widgets/section.dart';
|
||||
import '../widgets/ui.dart';
|
||||
import 'league_view.dart';
|
||||
import 'settings_screen.dart';
|
||||
|
||||
enum EventType {
|
||||
@@ -32,7 +33,7 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
||||
bool _isLoading = false;
|
||||
List<CalendarEvent> _events = [];
|
||||
String? _errorMessage;
|
||||
bool _showContacts = false;
|
||||
int _tab = 0; // 0 calendar, 1 contacts, 2 league
|
||||
String _query = '';
|
||||
|
||||
List<Contact> get _contacts => AppSettings.instance.clubContacts;
|
||||
@@ -534,8 +535,10 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
||||
listenable: AppSettings.instance,
|
||||
builder: (context, _) {
|
||||
Widget body;
|
||||
if (_showContacts) {
|
||||
if (_tab == 1) {
|
||||
body = _buildContactsList();
|
||||
} else if (_tab == 2) {
|
||||
body = const LeagueView(); // loads each time the tab is opened
|
||||
} else if (_isLoading && _events.isEmpty) {
|
||||
body = const Center(child: CircularProgressIndicator());
|
||||
} else if (_errorMessage != null && _events.isEmpty) {
|
||||
@@ -567,9 +570,10 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
||||
tabs: [
|
||||
BarTab(_t('Calendar'), Icons.calendar_today_outlined),
|
||||
BarTab(_t('Contacts'), Icons.person_add_alt_outlined),
|
||||
BarTab(_t('League'), Icons.emoji_events_outlined),
|
||||
],
|
||||
selected: _showContacts ? 1 : 0,
|
||||
onSelect: (i) => setState(() => _showContacts = i == 1),
|
||||
selected: _tab,
|
||||
onSelect: (i) => setState(() => _tab = i),
|
||||
),
|
||||
Expanded(child: body),
|
||||
],
|
||||
|
||||
@@ -0,0 +1,305 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../services/app_settings.dart';
|
||||
import '../services/league_service.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import '../widgets/ui.dart';
|
||||
import 'session_screen.dart' show targetCount, shotCount;
|
||||
|
||||
/// Koledar → Liga: the club league from liga.bl3kunja.top – which tournament
|
||||
/// is open, the plan of all of them, and the live standings. Read when the
|
||||
/// tab is opened (and on pull to refresh), never in the background.
|
||||
class LeagueView extends StatefulWidget {
|
||||
final LeagueService? service; // tests pass one with a fake client
|
||||
const LeagueView({super.key, this.service});
|
||||
|
||||
@override
|
||||
State<LeagueView> createState() => _LeagueViewState();
|
||||
}
|
||||
|
||||
class _LeagueViewState extends State<LeagueView> {
|
||||
static const String _ourClub = 'Kovinar'; // our shooters are highlighted
|
||||
|
||||
late final LeagueService _service = widget.service ?? LeagueService();
|
||||
LeagueStandings? _data;
|
||||
Object? _error;
|
||||
bool _loading = true;
|
||||
|
||||
String _t(String key) => AppSettings.instance.t(key);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_load();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_service.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
setState(() => _loading = true);
|
||||
try {
|
||||
final data = await _service.standings();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_data = data;
|
||||
_error = null;
|
||||
_loading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_error = e;
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openSite() =>
|
||||
launchUrl(Uri.parse('${LeagueService.site}/lestvica'), mode: LaunchMode.externalApplication);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = _data;
|
||||
if (data == null) {
|
||||
if (_loading) return const Center(child: CircularProgressIndicator());
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: EmptyState(
|
||||
icon: Icons.cloud_off_rounded,
|
||||
title: _t('Could not load the league'),
|
||||
hint: '$_error',
|
||||
action: SizedBox(
|
||||
width: 180,
|
||||
child: PrimaryButton(label: _t('Retry'), icon: Icons.refresh_rounded, height: 46, onTap: _load),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return RefreshIndicator(
|
||||
onRefresh: _load,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(AppTheme.edge, 0, AppTheme.edge, 24),
|
||||
children: [
|
||||
_statusCard(data),
|
||||
const SizedBox(height: 12),
|
||||
_standingsCard(data),
|
||||
const SizedBox(height: 12),
|
||||
SoftButton(label: _t('Open the league website'), icon: Icons.open_in_new_rounded, onTap: _openSite),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Which tournament is open (or next), the plan of all of them, the rules
|
||||
Widget _statusCard(LeagueStandings data) {
|
||||
final c = Palette.current;
|
||||
final open = data.openRound;
|
||||
final next = data.nextRound;
|
||||
final day = DateFormat('d. M.');
|
||||
final (String title, String? sub, Color dot) = open != null
|
||||
? (
|
||||
_t('{n}. tournament is open').replaceAll('{n}', '${open.number}'),
|
||||
[
|
||||
if (open.endsAt != null) _t('until {d}').replaceAll('{d}', day.format(open.endsAt!)),
|
||||
_t('Entries: {n}').replaceAll('{n}', '${open.submissions}'),
|
||||
].join(' · '),
|
||||
c.pos,
|
||||
)
|
||||
: next != null
|
||||
? (
|
||||
_t('{n}. tournament').replaceAll('{n}', '${next.number}'),
|
||||
next.startsAt == null ? null : _t('from {d}').replaceAll('{d}', day.format(next.startsAt!)),
|
||||
c.muted,
|
||||
)
|
||||
: (_t('The league has finished'), null, c.faint);
|
||||
return AppCard(
|
||||
padding: const EdgeInsets.fromLTRB(16, 14, 16, 14),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Kicker(data.league.name),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Container(width: 9, height: 9, decoration: BoxDecoration(color: dot, shape: BoxShape.circle)),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: Text(title, style: TextStyle(fontSize: 18, fontWeight: FontWeight.w700, color: c.ink))),
|
||||
],
|
||||
),
|
||||
if (sub != null) ...[
|
||||
const SizedBox(height: 2),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 17),
|
||||
child: Text(sub, style: TextStyle(fontSize: 13, color: c.muted)),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 14),
|
||||
Row(
|
||||
children: [
|
||||
for (int i = 0; i < data.rounds.length; i++) ...[
|
||||
if (i > 0) const SizedBox(width: 6),
|
||||
Expanded(child: _roundChip(data.rounds[i])),
|
||||
],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
[
|
||||
_t('Best {n} count').replaceAll('{n}', '${data.league.counted}'),
|
||||
targetCount(data.league.targets),
|
||||
shotCount(data.league.shots),
|
||||
].join(' · '),
|
||||
style: TextStyle(fontSize: 12, color: c.muted),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// One tournament of the plan: open in the accent, done ticked, to come faint
|
||||
Widget _roundChip(LeagueRound r) {
|
||||
final c = Palette.current;
|
||||
final month = r.startsAt == null
|
||||
? ''
|
||||
: DateFormat('LLL', AppSettings.instance.dateLocale).format(r.startsAt!).replaceAll('.', '');
|
||||
final fg = r.isOpen ? c.onAccent : (r.isDone ? c.ink2 : c.faint);
|
||||
return Container(
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: r.isOpen ? c.accent : (r.isDone ? c.tile : Colors.transparent),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: r.isUpcoming ? Border.all(color: c.line) : null,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (r.isDone) ...[Icon(Icons.check_rounded, size: 13, color: fg), const SizedBox(width: 2)],
|
||||
Text('${r.number}.', style: TextStyle(fontSize: 15, fontWeight: FontWeight.w800, color: fg)),
|
||||
],
|
||||
),
|
||||
Text(month, style: TextStyle(fontSize: 10.5, fontWeight: FontWeight.w600, color: fg.withValues(alpha: 0.8))),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _standingsCard(LeagueStandings data) {
|
||||
final c = Palette.current;
|
||||
// Only tournaments that have started get a column, so early in the season
|
||||
// names have room; the plan of all of them is in the status card
|
||||
final rounds = data.rounds.where((r) => !r.isUpcoming).length.clamp(1, data.rounds.length);
|
||||
return AppCard(
|
||||
padding: const EdgeInsets.fromLTRB(12, 14, 12, 6),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 4, bottom: 6),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: Kicker(_t('Standings'))),
|
||||
for (int i = 1; i <= rounds; i++)
|
||||
SizedBox(width: 30, child: Text('$i.', textAlign: TextAlign.center, style: AppTheme.kicker(c))),
|
||||
SizedBox(width: 48, child: Text('Σ', textAlign: TextAlign.right, style: AppTheme.kicker(c))),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (data.players.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 20),
|
||||
child: Text(_t('No results yet'), textAlign: TextAlign.center, style: TextStyle(color: c.muted)),
|
||||
),
|
||||
for (final p in data.players) _playerRow(p, rounds),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _playerRow(LeaguePlayer p, int rounds) {
|
||||
final c = Palette.current;
|
||||
final ours = p.club.contains(_ourClub);
|
||||
// 1–3 in gold, silver and bronze
|
||||
final medal = switch (p.rank) {
|
||||
1 => c.gold,
|
||||
2 => const Color(0xFFB8BEC6),
|
||||
3 => const Color(0xFFCD8B4E),
|
||||
_ => null,
|
||||
};
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 4),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 7),
|
||||
decoration: BoxDecoration(
|
||||
color: ours ? c.accentSoft : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 26,
|
||||
height: 26,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: medal?.withValues(alpha: 0.22) ?? c.tile,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Text('${p.rank}',
|
||||
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w800, color: medal ?? c.ink2, fontFeatures: AppTheme.tnum)),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(p.name,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w700, color: c.ink)),
|
||||
Text(p.club,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 11.5, color: ours ? c.accent : c.muted, fontWeight: ours ? FontWeight.w600 : null)),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Each tournament: counted ones plain, dropped ones struck through
|
||||
for (int i = 0; i < rounds; i++)
|
||||
SizedBox(
|
||||
width: 30,
|
||||
child: Text(
|
||||
i < p.cells.length && p.cells[i] != null ? '${p.cells[i]!.score}' : '–',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontFeatures: AppTheme.tnum,
|
||||
color: i < p.cells.length && p.cells[i] != null ? (p.cells[i]!.counted ? c.ink2 : c.faint) : c.faint,
|
||||
decoration: i < p.cells.length && p.cells[i] != null && !p.cells[i]!.counted ? TextDecoration.lineThrough : null,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 48,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text('${p.finalScore}',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w800, color: c.ink, fontFeatures: AppTheme.tnum)),
|
||||
Text('${p.tens}×10', style: TextStyle(fontSize: 10.5, color: c.muted, fontFeatures: AppTheme.tnum)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+207
-109
@@ -20,12 +20,27 @@ import 'yolo_detector.dart';
|
||||
/// "Preveri zadetke": the detected hits on the chosen target design. Tap a
|
||||
/// tile to pick a hit, then hold and drag on the target to move it; add or
|
||||
/// remove hits; choose where to save; save.
|
||||
///
|
||||
/// [PreviewScreen.edit] opens a saved target the same way: its hits, no photo
|
||||
/// and no folder choice; saving overwrites that target's file.
|
||||
class PreviewScreen extends StatefulWidget {
|
||||
final String imagePath;
|
||||
final String? imagePath;
|
||||
final List<DetectionResult> detections;
|
||||
final int bulletCount;
|
||||
final File? editFile; // the saved target being edited
|
||||
final List<Offset> initialHits;
|
||||
|
||||
const PreviewScreen({super.key, required this.imagePath, required this.detections, required this.bulletCount});
|
||||
const PreviewScreen({super.key, required String this.imagePath, required this.detections, required this.bulletCount})
|
||||
: editFile = null,
|
||||
initialHits = const [];
|
||||
|
||||
const PreviewScreen.edit({super.key, required File file, required List<Offset> hits, required this.bulletCount})
|
||||
: imagePath = null,
|
||||
detections = const [],
|
||||
editFile = file,
|
||||
initialHits = hits;
|
||||
|
||||
bool get isEdit => editFile != null;
|
||||
|
||||
@override
|
||||
State<PreviewScreen> createState() => _PreviewScreenState();
|
||||
@@ -68,7 +83,11 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
await Future.wait([_loadFolders(), _runDetectionAndMapping()]);
|
||||
if (widget.isEdit) {
|
||||
_hits = [...widget.initialHits];
|
||||
} else {
|
||||
await Future.wait([_loadFolders(), _runDetectionAndMapping()]);
|
||||
}
|
||||
if (mounted) setState(() => _isLoading = false);
|
||||
}
|
||||
|
||||
@@ -106,7 +125,7 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
||||
|
||||
Future<void> _runDetectionAndMapping() async {
|
||||
try {
|
||||
final bytes = await File(widget.imagePath).readAsBytes();
|
||||
final bytes = await File(widget.imagePath!).readAsBytes();
|
||||
_photo = bytes;
|
||||
_photoSize = await _imageSize(bytes);
|
||||
|
||||
@@ -232,9 +251,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
||||
final i = _selected;
|
||||
if (i == null) return;
|
||||
setState(() {
|
||||
final p = _hits[i] + delta;
|
||||
// Keep it on the canvas
|
||||
_hits[i] = Offset(p.dx.clamp(0, TargetScoring.size), p.dy.clamp(0, TargetScoring.size));
|
||||
// Keep it within the target's square
|
||||
_hits[i] = TargetScoring.shown(_hits[i] + delta);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -285,7 +303,30 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
// Edit: the same file with the new hits; everything else in it is kept
|
||||
Future<void> _saveEdit() async {
|
||||
final file = widget.editFile!;
|
||||
if (_saving) return;
|
||||
setState(() => _saving = true);
|
||||
try {
|
||||
final data = jsonDecode(await file.readAsString()) as Map<String, dynamic>;
|
||||
final scores = [for (int i = 0; i < _hits.length; i++) _scoreAt(i)];
|
||||
data['totalScore'] = scores.fold(0, (a, b) => a + b);
|
||||
data['bulletCount'] = widget.bulletCount;
|
||||
data['bullets'] = [for (final b in _hits) {'x': b.dx, 'y': b.dy}];
|
||||
data['scores'] = scores;
|
||||
await file.writeAsString(jsonEncode(data));
|
||||
TargetRepository.notifyChanged();
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
debugPrint('Error saving edited target: $e');
|
||||
if (mounted) setState(() => _saving = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
if (widget.isEdit) return _saveEdit();
|
||||
final to = _saveTo;
|
||||
if (to == null || _saving) return;
|
||||
setState(() => _saving = true);
|
||||
@@ -327,8 +368,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
||||
showHelpSheet(context, t: _t, items: const [
|
||||
(Icons.touch_app_outlined, 'Tap a value below to pick that hit; it gets a red border.'),
|
||||
(Icons.open_with_rounded, 'Hold and drag on the target to move the picked hit; a magnifier shows where it is.'),
|
||||
(Icons.add_rounded, 'Add hit: for a shot that was not found. Remove hit: deletes the picked one.'),
|
||||
(Icons.folder_outlined, 'Save to: training or tournament, and which folder. The last one is chosen for you.'),
|
||||
(Icons.add_box_outlined, '+ tile: for a shot that was not found. Bin: deletes the picked hit.'),
|
||||
(Icons.emoji_events_outlined, 'Button bottom left: training or tournament. The folder on top: where it is saved; the last one is chosen for you.'),
|
||||
(Icons.photo_outlined, 'Photo icon: see the photo with what was detected.'),
|
||||
]);
|
||||
}
|
||||
@@ -338,77 +379,118 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
||||
final s = AppSettings.instance;
|
||||
final c = Palette.current;
|
||||
final found = widget.detections.where((r) => r.classId == 0).length;
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
// The picked target's own background (a holiday's wins)
|
||||
return AppBackground(
|
||||
target: true,
|
||||
child: Scaffold(
|
||||
// Laid out on the target background's zones: header and "save to" above
|
||||
// its first line, the target in the window between the lines, the hits
|
||||
// and buttons below the second one
|
||||
body: Stack(
|
||||
children: [
|
||||
BackHeader(
|
||||
title: _t('Check hits'),
|
||||
subtitle: _t('{n} hits detected · correct them if needed').replaceAll('{n}', '${min(found, widget.bulletCount)}'),
|
||||
actions: [CircleButton(icon: Icons.info_outline_rounded, onTap: _showHelp)],
|
||||
),
|
||||
if (_isLoading)
|
||||
const Expanded(child: Center(child: CircularProgressIndicator()))
|
||||
else ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(AppTheme.edge, 4, AppTheme.edge, 0),
|
||||
child: _saveCard(c),
|
||||
),
|
||||
Expanded(
|
||||
if (!_isLoading)
|
||||
TargetWindow(
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(child: _showPhoto ? _photoView(c) : _targetView(s, c)),
|
||||
// The photo with what the model saw, for checking
|
||||
Positioned(
|
||||
top: 8,
|
||||
right: AppTheme.edge,
|
||||
child: CircleButton(
|
||||
icon: _showPhoto ? Icons.track_changes_rounded : Icons.photo_outlined,
|
||||
size: 36,
|
||||
iconSize: 18,
|
||||
tooltip: _t(_showPhoto ? 'Show Mapped Target' : 'Show Camera Detections'),
|
||||
onTap: () => setState(() => _showPhoto = !_showPhoto),
|
||||
// The photo with what the model saw, for checking (a saved
|
||||
// target has no photo): the window's top right corner
|
||||
if (!widget.isEdit)
|
||||
Positioned(
|
||||
top: 10,
|
||||
right: AppTheme.edge,
|
||||
child: CircleButton(
|
||||
icon: _showPhoto ? Icons.track_changes_rounded : Icons.photo_outlined,
|
||||
size: 40,
|
||||
iconSize: 19,
|
||||
tooltip: _t(_showPhoto ? 'Show Mapped Target' : 'Show Camera Detections'),
|
||||
onTap: () => setState(() => _showPhoto = !_showPhoto),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(AppTheme.edge, 0, AppTheme.edge, 0),
|
||||
child: _tiles(c),
|
||||
// The folder it is saved to sits on the target window's upper line
|
||||
if (!_isLoading && !widget.isEdit)
|
||||
Positioned.fill(
|
||||
child: LayoutBuilder(builder: (context, box) {
|
||||
// From under the header (60 + the status bar) down to just
|
||||
// above the line: it grows with the room the screen has
|
||||
final (line, _) = TargetWindow.lines(box.biggest);
|
||||
final bottom = line - 12;
|
||||
final top = min(MediaQuery.paddingOf(context).top + 60 + 6, bottom - 56);
|
||||
return Stack(children: [
|
||||
Positioned(left: AppTheme.edge, right: AppTheme.edge, top: top, height: bottom - top, child: _saveCard(c)),
|
||||
]);
|
||||
}),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(AppTheme.edge, 12, AppTheme.edge, 0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SoftButton(
|
||||
label: _t('Add hit'),
|
||||
icon: Icons.add_rounded,
|
||||
onTap: _hits.length < widget.bulletCount ? _addHit : null,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: SoftButton(
|
||||
label: _t('Remove hit'),
|
||||
icon: Icons.delete_outline_rounded,
|
||||
destructive: _selected != null,
|
||||
onTap: _selected == null ? null : _removeHit,
|
||||
),
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
BackHeader(
|
||||
title: _t(widget.isEdit ? 'Edit target' : 'Check hits'),
|
||||
subtitle: widget.isEdit
|
||||
? widget.editFile!.parent.path.split('/').last
|
||||
: _t('{n} hits detected').replaceAll('{n}', '${min(found, widget.bulletCount)}'),
|
||||
actions: [
|
||||
CircleButton(icon: Icons.info_outline_rounded, onTap: _showHelp),
|
||||
],
|
||||
),
|
||||
if (_isLoading)
|
||||
const Expanded(child: Center(child: CircularProgressIndicator()))
|
||||
else ...[
|
||||
const Spacer(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(AppTheme.edge, 8, AppTheme.edge, 0),
|
||||
child: _tiles(c),
|
||||
),
|
||||
_actions(c),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Like the result page: a square button either side of the main one
|
||||
Widget _actions(Palette c) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.fromLTRB(AppTheme.edge, 16, AppTheme.edge, 12 + MediaQuery.paddingOf(context).bottom),
|
||||
child: Row(
|
||||
children: [
|
||||
// Training or tournament: one tap switches (and the folder with it)
|
||||
if (!widget.isEdit) ...[
|
||||
SquareButton(
|
||||
size: 52,
|
||||
icon: _tournament ? Icons.emoji_events_outlined : Icons.track_changes_rounded,
|
||||
color: _tournament ? c.gold : c.accent,
|
||||
background: _tournament ? c.goldSoft : c.accentSoft,
|
||||
tooltip: _t(_tournament ? 'Tournament' : 'Training'),
|
||||
onTap: () {
|
||||
HapticFeedback.selectionClick();
|
||||
_setKind(!_tournament);
|
||||
},
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(AppTheme.edge, 16, AppTheme.edge, 12 + MediaQuery.paddingOf(context).bottom),
|
||||
child: PrimaryButton(
|
||||
label: '${_t('Save target')} · $_total',
|
||||
icon: Icons.check_rounded,
|
||||
busy: _saving,
|
||||
onTap: _save,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
],
|
||||
Expanded(
|
||||
child: PrimaryButton(
|
||||
label: '${_t(widget.isEdit ? 'Save changes' : 'Save target')} · $_total',
|
||||
icon: Icons.check_rounded,
|
||||
busy: _saving,
|
||||
onTap: _save,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
SquareButton(
|
||||
size: 52,
|
||||
icon: Icons.delete_outline_rounded,
|
||||
tooltip: _t('Remove hit'),
|
||||
color: _selected == null ? c.faint : c.red,
|
||||
background: _selected == null ? null : c.redSoft,
|
||||
onTap: _selected == null ? null : _removeHit,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -423,48 +505,63 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
||||
: DateUtils.isSameDay(to.date, DateTime.now())
|
||||
? '${_t('today')} ${DateFormat('HH:mm').format(to.date!)}'
|
||||
: DateFormat('d. M.').format(to.date ?? DateTime.now());
|
||||
return AppCard(
|
||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Kicker(_t('Save to'), padding: const EdgeInsets.only(left: 2, bottom: 8)),
|
||||
SegmentedTabs(
|
||||
height: 40,
|
||||
items: [SegmentItem(_t('Training')), SegmentItem(_t('Tournament'))],
|
||||
selected: _tournament ? 1 : 0,
|
||||
onSelect: (i) => _setKind(i == 1),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Material(
|
||||
color: c.isDark ? c.card : c.card,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12), side: BorderSide(color: c.line)),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: _pickFolder,
|
||||
child: SizedBox(
|
||||
height: 42,
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 12),
|
||||
Icon(Icons.folder_outlined, size: 18, color: c.accent),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: Text(to?.name ?? '',
|
||||
// The folder, with the kind above its name (switched by the button
|
||||
// bottom left); fills the room between the header and the line
|
||||
final tint = _tournament ? c.gold : c.accent;
|
||||
return Material(
|
||||
color: c.card,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16), side: BorderSide(color: c.line)),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: _pickFolder,
|
||||
child: LayoutBuilder(builder: (context, box) {
|
||||
final roomy = box.maxHeight >= 76;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: roomy ? 48 : 34,
|
||||
height: roomy ? 48 : 34,
|
||||
decoration: BoxDecoration(
|
||||
color: _tournament ? c.goldSoft : c.accentSoft,
|
||||
borderRadius: BorderRadius.circular(roomy ? 14 : 10),
|
||||
),
|
||||
child: Icon(Icons.folder_outlined, size: roomy ? 24 : 18, color: tint),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('${_t('Save to')} · ${_t(_tournament ? 'Tournament' : 'Training')}'.toUpperCase(),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: c.ink)),
|
||||
),
|
||||
Text(' · $when', style: TextStyle(fontSize: 12.5, color: c.muted)),
|
||||
const Spacer(),
|
||||
Icon(Icons.expand_more_rounded, size: 20, color: c.muted),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
style: AppTheme.kicker(c).copyWith(fontSize: roomy ? 10.5 : 9.5)),
|
||||
SizedBox(height: roomy ? 4 : 2),
|
||||
Text(to?.name ?? '',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: roomy ? 19 : 15, height: 1.15, fontWeight: FontWeight.w700, color: c.ink)),
|
||||
if (roomy && when.isNotEmpty) ...[
|
||||
const SizedBox(height: 3),
|
||||
Text(when, maxLines: 1, style: TextStyle(fontSize: 12.5, color: c.muted)),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!roomy && when.isNotEmpty) ...[Text(when, style: TextStyle(fontSize: 12, color: c.muted)), const SizedBox(width: 4)],
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(color: c.tile, shape: BoxShape.circle),
|
||||
child: Icon(Icons.unfold_more_rounded, size: 18, color: c.ink2),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -475,17 +572,18 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
||||
final side = min(box.maxWidth, box.maxHeight) - 8;
|
||||
if (side <= 0) return const SizedBox();
|
||||
final scale = side / TargetScoring.size;
|
||||
Offset toTarget(Offset screen) => screen / scale;
|
||||
final i = _selected;
|
||||
final picked = i == null || i >= _hits.length ? null : _hits[i] * scale;
|
||||
final picked = i == null || i >= _hits.length ? null : TargetScoring.shown(_hits[i]) * scale;
|
||||
return Center(
|
||||
child: SizedBox.square(
|
||||
dimension: side,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTapUp: (d) => _pickAt(d.localPosition / scale),
|
||||
onTapUp: (d) => _pickAt(toTarget(d.localPosition)),
|
||||
onPanStart: (d) {
|
||||
// Starting on another hit picks that one
|
||||
final near = _nearest(d.localPosition / scale);
|
||||
final near = _nearest(toTarget(d.localPosition));
|
||||
if (near != null) _selected = near;
|
||||
if (_selected == null) return;
|
||||
HapticFeedback.selectionClick();
|
||||
@@ -544,7 +642,7 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
||||
int? best;
|
||||
var bestD = 60.0; // target units: a little more than a hit's radius
|
||||
for (int i = 0; i < _hits.length; i++) {
|
||||
final d = (_hits[i] - p).distance;
|
||||
final d = (TargetScoring.shown(_hits[i]) - p).distance; // where it is drawn
|
||||
if (d < bestD) {
|
||||
bestD = d;
|
||||
best = i;
|
||||
|
||||
@@ -168,6 +168,7 @@ class _SessionScreenState extends State<SessionScreen> {
|
||||
style: s.target,
|
||||
hits: _hits[target.file.path]?.bullets ?? const [],
|
||||
hitColor: s.bulletColor,
|
||||
zoomToHits: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
|
||||
@@ -151,11 +151,14 @@ class SettingsScreen extends StatelessWidget {
|
||||
),
|
||||
FutureBuilder<PackageInfo>(
|
||||
future: _packageInfo,
|
||||
// Debug builds: long press previews a holiday
|
||||
builder: (context, snap) => SettingsTile(
|
||||
icon: Icons.info_outline_rounded,
|
||||
title: t('Version'),
|
||||
value: snap.data?.version ?? '',
|
||||
// Hidden (any build): long press previews a holiday
|
||||
builder: (context, snap) => GestureDetector(
|
||||
onLongPress: () => _previewHoliday(context),
|
||||
child: SettingsTile(
|
||||
icon: Icons.info_outline_rounded,
|
||||
title: t('Version'),
|
||||
value: snap.data?.version ?? '',
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
@@ -168,7 +171,7 @@ class SettingsScreen extends StatelessWidget {
|
||||
icon: Icons.celebration_outlined,
|
||||
title: 'Holiday preview',
|
||||
subtitle: 'Shows the app as on a day of the holiday',
|
||||
value: s.debugToday == null ? 'Today' : (s.holiday?.name ?? 'Today'),
|
||||
value: s.debugNoHoliday ? 'Default' : (s.debugToday == null ? 'Today' : (s.holiday?.name ?? 'Today')),
|
||||
onTap: () => _previewHoliday(context),
|
||||
),
|
||||
]),
|
||||
@@ -195,13 +198,24 @@ class SettingsScreen extends StatelessWidget {
|
||||
children: [
|
||||
SheetOption(
|
||||
label: 'Today',
|
||||
selected: s.debugToday == null,
|
||||
subtitle: s.debugToday == null && !s.debugNoHoliday ? null : 'The real date',
|
||||
selected: s.debugToday == null && !s.debugNoHoliday,
|
||||
showDivider: false,
|
||||
onTap: () {
|
||||
s.previewDay(null);
|
||||
Navigator.pop(sheet);
|
||||
},
|
||||
),
|
||||
SheetOption(
|
||||
label: 'Default (no holiday)',
|
||||
subtitle: 'Everyday look, your own target and colour',
|
||||
leading: TargetThumb(s.ownTarget, size: 32),
|
||||
selected: s.debugNoHoliday,
|
||||
onTap: () {
|
||||
s.previewDay(null, noHoliday: true);
|
||||
Navigator.pop(sheet);
|
||||
},
|
||||
),
|
||||
for (final h in HolidayTheme.all)
|
||||
Builder(builder: (_) {
|
||||
// First day of the holiday this year
|
||||
@@ -213,7 +227,7 @@ class SettingsScreen extends StatelessWidget {
|
||||
label: h.name,
|
||||
subtitle: '${DateFormat('d. M.').format(start)} – ${DateFormat('d. M.').format(end)}',
|
||||
leading: TargetThumb(TargetStyle.byId(h.targetId), size: 32),
|
||||
selected: s.holiday == h && s.debugToday != null,
|
||||
selected: s.holiday == h && s.debugToday != null && !s.debugNoHoliday,
|
||||
onTap: () {
|
||||
s.previewDay(day);
|
||||
Navigator.pop(sheet);
|
||||
@@ -371,22 +385,32 @@ void showAppearanceSheet(BuildContext context) {
|
||||
children: [
|
||||
SheetTitle(s.t('Appearance'), trailing: TargetThumb(s.target, size: 52)),
|
||||
Kicker(s.t('Bullet color'), padding: const EdgeInsets.only(bottom: 12)),
|
||||
// During a holiday its colour gets its own line first (and is the
|
||||
// one in use until another is picked)
|
||||
if (s.holiday != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: GestureDetector(
|
||||
onTap: s.useHolidayColor,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Row(
|
||||
children: [
|
||||
_ColorDot(s.holiday!.color, size: 32, selected: s.holidayColorActive),
|
||||
const SizedBox(width: 10),
|
||||
Text(s.holiday!.name, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Palette.current.ink2)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
// Two rows of 8, round the colour wheel
|
||||
LayoutBuilder(builder: (context, box) {
|
||||
const perRow = 8;
|
||||
final size = ((box.maxWidth - (perRow - 1) * 10) / perRow).clamp(28.0, 40.0);
|
||||
final gap = (box.maxWidth - perRow * size) / (perRow - 1);
|
||||
return Wrap(
|
||||
spacing: 10,
|
||||
spacing: gap - 0.01, // exactly 8 per row at any width
|
||||
runSpacing: 12,
|
||||
children: [
|
||||
// During a holiday its colour comes first (and is the one in use)
|
||||
if (s.holiday != null)
|
||||
GestureDetector(
|
||||
onTap: s.useHolidayColor,
|
||||
child: Tooltip(
|
||||
message: s.holiday!.name,
|
||||
child: _ColorDot(s.holiday!.color, size: size, selected: s.holidayColorActive),
|
||||
),
|
||||
),
|
||||
for (final name in AppSettings.bulletColors.keys)
|
||||
GestureDetector(
|
||||
onTap: () => s.setBulletColor(name),
|
||||
@@ -408,13 +432,20 @@ void showAppearanceSheet(BuildContext context) {
|
||||
);
|
||||
}
|
||||
|
||||
/// Three target designs per row; the chosen one has an accent border and a check.
|
||||
/// Three target designs per row; the chosen one has an accent border.
|
||||
class _TargetGrid extends StatelessWidget {
|
||||
final List<TargetStyle> styles;
|
||||
const _TargetGrid({required this.styles});
|
||||
|
||||
// Listens itself: the sheet builds it as a const, so the sheet's own
|
||||
// rebuild never reaches it and the check would stay on the old target
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context) => ListenableBuilder(
|
||||
listenable: AppSettings.instance,
|
||||
builder: (context, _) => _grid(),
|
||||
);
|
||||
|
||||
Widget _grid() {
|
||||
final s = AppSettings.instance;
|
||||
final c = Palette.current;
|
||||
return LayoutBuilder(builder: (context, box) {
|
||||
@@ -430,31 +461,16 @@ class _TargetGrid extends StatelessWidget {
|
||||
onTap: () => s.setTarget(style),
|
||||
child: Column(
|
||||
children: [
|
||||
Stack(
|
||||
children: [
|
||||
Container(
|
||||
height: w * 0.92,
|
||||
width: w,
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: c.isDark ? c.card2 : c.tile,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: style == s.target ? c.accent : Colors.transparent, width: 2),
|
||||
),
|
||||
child: Center(child: TargetThumb(style, size: w * 0.92 - 16)),
|
||||
),
|
||||
if (style == s.target)
|
||||
Positioned(
|
||||
top: 6,
|
||||
right: 6,
|
||||
child: Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
decoration: BoxDecoration(color: c.accent, shape: BoxShape.circle),
|
||||
child: Icon(Icons.check_rounded, size: 14, color: c.onAccent),
|
||||
),
|
||||
),
|
||||
],
|
||||
Container(
|
||||
height: w * 0.92,
|
||||
width: w,
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: c.isDark ? c.card2 : c.tile,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: style == s.target ? c.accent : Colors.transparent, width: 2),
|
||||
),
|
||||
child: Center(child: TargetThumb(style, size: w * 0.92 - 16)),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
|
||||
@@ -193,26 +193,27 @@ class _TargetScreenState extends State<TargetScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// A ready camera: the hit colour over the whole tile, a solid icon and the
|
||||
// name in one colour. One not set up is dashed.
|
||||
// A ready camera: a normal card outlined in the hit colour, its icon on a
|
||||
// soft badge of that colour, the name in the text colour. One not set up is
|
||||
// dashed, with a plus.
|
||||
Widget _cameraTile(AppSettings s, Palette c, int position, bool ready) {
|
||||
final name = '${s.t('Camera')} $position';
|
||||
final fill = c.accent;
|
||||
final fg = ready ? Palette.onColor(fill) : c.ink2;
|
||||
final content = Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ready
|
||||
? Icon(Icons.videocam_rounded, size: 36, color: fg)
|
||||
: Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(color: c.tile, borderRadius: BorderRadius.circular(14)),
|
||||
child: Icon(Icons.add_rounded, size: 26, color: c.muted),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(name, textAlign: TextAlign.center, style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700, color: fg)),
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(color: ready ? c.accentSoft : c.tile, borderRadius: BorderRadius.circular(14)),
|
||||
child: ready
|
||||
? Icon(Icons.videocam_rounded, size: 26, color: c.accent)
|
||||
: Icon(Icons.add_rounded, size: 26, color: c.muted),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(name,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700, color: ready ? c.ink : c.ink2)),
|
||||
if (!ready)
|
||||
Text(s.t('Not set up'), textAlign: TextAlign.center, style: TextStyle(fontSize: 11.5, color: c.faint)),
|
||||
],
|
||||
@@ -220,8 +221,8 @@ class _TargetScreenState extends State<TargetScreen> {
|
||||
);
|
||||
return AppCard(
|
||||
dashed: !ready,
|
||||
color: ready ? fill : null,
|
||||
borderColor: ready ? fill : null,
|
||||
borderColor: ready ? c.accent : null,
|
||||
borderWidth: ready ? 1.5 : 1,
|
||||
padding: const EdgeInsets.all(10),
|
||||
onTap: () => _openPosition(position),
|
||||
child: content,
|
||||
@@ -244,6 +245,7 @@ class _TargetScreenState extends State<TargetScreen> {
|
||||
style: s.target,
|
||||
hits: _lastHits?.bullets ?? const [],
|
||||
hitColor: s.bulletColor,
|
||||
zoomToHits: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
|
||||
@@ -10,7 +10,8 @@ import '../widgets/bar_list.dart';
|
||||
import '../widgets/result_share.dart';
|
||||
import '../widgets/target_face.dart';
|
||||
import '../widgets/ui.dart';
|
||||
import 'session_screen.dart' show targetCount, shotCount, confirmDelete;
|
||||
import 'preview_screen.dart';
|
||||
import 'session_screen.dart' show SessionScreen, targetCount, shotCount, confirmDelete;
|
||||
|
||||
/// The result of one target, or of a whole session on one target
|
||||
/// ([isCombinedView]): the score, the target with every hit, the hits grouped
|
||||
@@ -32,6 +33,8 @@ class TargetViewScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
// The targets shown; deleting some from the session list shortens it
|
||||
late List<File> _files = widget.jsonFiles;
|
||||
List<TargetHits>? _targets; // one per file, in the order given
|
||||
TargetHits _all = TargetHits.empty;
|
||||
int? _number; // 1-based number of a single target in its session
|
||||
@@ -41,7 +44,7 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
bool _showScoring = false; // debug builds: long press the target
|
||||
final _zoom = TransformationController();
|
||||
|
||||
String get _folder => widget.jsonFiles.first.parent.path.split('/').last;
|
||||
String get _folder => _files.first.parent.path.split('/').last;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -56,7 +59,7 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
final targets = await TargetRepository.readAllHits(widget.jsonFiles);
|
||||
final targets = await TargetRepository.readAllHits(_files);
|
||||
int? number;
|
||||
DateTime? date;
|
||||
final sessions = await TargetRepository.loadSessions();
|
||||
@@ -65,7 +68,7 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
date = session.date;
|
||||
if (!widget.isCombinedView) {
|
||||
final i = session.targets
|
||||
.indexWhere((t) => t.file.path == widget.jsonFiles.first.path);
|
||||
.indexWhere((t) => t.file.path == _files.first.path);
|
||||
if (i >= 0) {
|
||||
number = i + 1;
|
||||
date = session.targets[i].shotAt;
|
||||
@@ -90,12 +93,50 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
'${p[2]}-${p[1].padLeft(2, '0')}-${p[0].padLeft(2, '0')}');
|
||||
}
|
||||
|
||||
// The editor of "Check hits" on this target's hits; saving overwrites the
|
||||
// file, then the result is read again
|
||||
Future<void> _editTarget() async {
|
||||
final target = _targets?.firstOrNull;
|
||||
if (target == null) return;
|
||||
final saved = await Navigator.push<bool>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => PreviewScreen.edit(
|
||||
file: _files.first,
|
||||
hits: target.bullets,
|
||||
bulletCount: target.shots < target.bullets.length ? target.bullets.length : target.shots,
|
||||
),
|
||||
),
|
||||
);
|
||||
if (saved != true || !mounted) return;
|
||||
await _load();
|
||||
widget.refreshFolders();
|
||||
}
|
||||
|
||||
// Session view: its training or tournament, to see, edit and delete each
|
||||
// target; back here, what is left of it is shown again
|
||||
Future<void> _openSession() async {
|
||||
final sessions = await TargetRepository.loadSessions();
|
||||
final session = sessions.where((x) => x.name == _folder).firstOrNull;
|
||||
if (session == null || !mounted) return;
|
||||
await Navigator.push(context, MaterialPageRoute(builder: (_) => SessionScreen(session: session)));
|
||||
if (!mounted) return;
|
||||
widget.refreshFolders();
|
||||
final left = [for (final f in _files) if (f.existsSync()) f];
|
||||
if (left.isEmpty) {
|
||||
Navigator.pop(context); // every target was deleted
|
||||
return;
|
||||
}
|
||||
_files = left;
|
||||
await _load();
|
||||
}
|
||||
|
||||
Future<void> _deleteTarget() async {
|
||||
final s = AppSettings.instance;
|
||||
final ok = await confirmDelete(context, s.t('Are you sure you want to delete this target?'));
|
||||
if (!ok) return;
|
||||
try {
|
||||
await File(widget.jsonFiles.first.path).delete();
|
||||
await File(_files.first.path).delete();
|
||||
TargetRepository.notifyChanged();
|
||||
widget.refreshFolders();
|
||||
if (mounted) Navigator.pop(context);
|
||||
@@ -107,16 +148,16 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
// Values shown as tiles: 10 down to 7 always (so a missing 10 shows as 0×),
|
||||
// plus any lower value that was hit; at most 6 tiles.
|
||||
// Every value from 10 down to 0
|
||||
static const List<int> _values = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0];
|
||||
|
||||
// Only the values that were hit, best first: a tile each
|
||||
List<(int value, int count)> _groups() {
|
||||
final counts = <int, int>{};
|
||||
for (final v in _all.scores) {
|
||||
counts[v] = (counts[v] ?? 0) + 1;
|
||||
}
|
||||
final values = {10, 9, 8, 7, ...counts.keys}.toList()
|
||||
..sort((a, b) => b.compareTo(a));
|
||||
return [for (final v in values.take(6)) (v, counts[v] ?? 0)];
|
||||
return [for (final v in _values) if (counts[v] != null) (v, counts[v]!)];
|
||||
}
|
||||
|
||||
String get _title => widget.isCombinedView
|
||||
@@ -128,7 +169,7 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
if (widget.isCombinedView) {
|
||||
return [
|
||||
if (date != null) dayDate(date, year: true),
|
||||
targetCount(widget.jsonFiles.length),
|
||||
targetCount(_files.length),
|
||||
shotCount(_all.shots),
|
||||
].join(' · ');
|
||||
}
|
||||
@@ -170,7 +211,7 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
highlight: targets[i].total == best),
|
||||
]
|
||||
: [
|
||||
for (final v in [10, 9, 8, 7, 6])
|
||||
for (final (v, _) in _groups())
|
||||
BarEntry(
|
||||
'$v',
|
||||
_all.scores.where((x) => x == v).length.toDouble(),
|
||||
@@ -202,8 +243,16 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
final s = AppSettings.instance;
|
||||
final c = Palette.current;
|
||||
final loaded = _targets != null;
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
// The picked target's own background (a holiday's wins)
|
||||
return AppBackground(
|
||||
target: true,
|
||||
child: Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
// The target, zoomed or not, lives in the window the background
|
||||
// draws for it: between its score line and its dock line
|
||||
if (loaded && !_showChart) TargetWindow(child: _target(s)),
|
||||
Column(
|
||||
children: [
|
||||
BackHeader(
|
||||
title: loaded ? _title : '',
|
||||
@@ -214,12 +263,15 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
child: Center(child: CircularProgressIndicator()))
|
||||
else ...[
|
||||
_scoreRow(s, c),
|
||||
Expanded(child: _showChart ? _chart(s, c) : _target(s)),
|
||||
Expanded(child: _showChart ? _chart(s, c) : const SizedBox()),
|
||||
if (!_showChart) _tiles(c),
|
||||
_actions(s, c),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -273,7 +325,7 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// The target fills the free space; pinch to zoom in (the default target is
|
||||
// The target fills its window; pinch to zoom in (the default target is
|
||||
// vectors, so its lines stay sharp), double tap to zoom back out.
|
||||
Widget _target(AppSettings s) {
|
||||
final pressed = _pressedValue;
|
||||
@@ -303,6 +355,13 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
for (int i = 0; i < scores.length; i++)
|
||||
if (scores[i] == pressed) i
|
||||
},
|
||||
// The rest fade while a value is held, so its hits stand out
|
||||
dimmed: pressed == null
|
||||
? const {}
|
||||
: {
|
||||
for (int i = 0; i < scores.length; i++)
|
||||
if (scores[i] != pressed) i
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -313,25 +372,21 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
|
||||
Widget _tiles(Palette c) {
|
||||
final groups = _groups();
|
||||
final many = groups.length > 6;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(AppTheme.edge, 8, AppTheme.edge, 0),
|
||||
child: Row(
|
||||
child: TileRow(
|
||||
gap: many ? 4 : 10,
|
||||
children: [
|
||||
for (int i = 0; i < groups.length; i++) ...[
|
||||
if (i > 0) const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: ScoreTile(
|
||||
top: '${groups[i].$2}×',
|
||||
value: '${groups[i].$1}',
|
||||
filled: groups[i].$2 > 0,
|
||||
height: 64,
|
||||
onTapDown: groups[i].$2 == 0
|
||||
? null
|
||||
: (_) => setState(() => _pressedValue = groups[i].$1),
|
||||
onTapEnd: () => setState(() => _pressedValue = null),
|
||||
),
|
||||
for (final (value, count) in groups)
|
||||
ScoreTile(
|
||||
top: '$count×',
|
||||
value: '$value',
|
||||
height: many ? 56 : 64,
|
||||
radius: many ? 10 : 14,
|
||||
onTapDown: (_) => setState(() => _pressedValue = value),
|
||||
onTapEnd: () => setState(() => _pressedValue = null),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -379,6 +434,15 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
12 + MediaQuery.paddingOf(context).bottom),
|
||||
child: Row(
|
||||
children: [
|
||||
// A session: its target list, to see, edit and delete each one.
|
||||
// A single target: correct its hits.
|
||||
SquareButton(
|
||||
size: 52,
|
||||
icon: Icons.edit_outlined,
|
||||
tooltip: s.t(widget.isCombinedView ? 'Edit' : 'Edit target'),
|
||||
onTap: widget.isCombinedView ? _openSession : _editTarget,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: PrimaryButton(
|
||||
label: s.t('Share result'),
|
||||
|
||||
Reference in New Issue
Block a user