small updates
This commit is contained in:
+201
-173
@@ -4,6 +4,7 @@ import '../services/app_settings.dart';
|
||||
import '../services/target_repository.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import '../widgets/bar_tabs.dart';
|
||||
import '../widgets/help_sheet.dart';
|
||||
import '../widgets/progress_chart.dart';
|
||||
import '../widgets/section.dart';
|
||||
import 'session_screen.dart';
|
||||
@@ -125,12 +126,15 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
..sort((a, b) => counts[b]!.compareTo(counts[a]!));
|
||||
}
|
||||
|
||||
Future<void> _openSession(Session session) async {
|
||||
// Open the full session, not the copy limited to one format
|
||||
final full = _sessions!
|
||||
.firstWhere((s) => s.name == session.name, orElse: () => session);
|
||||
await Navigator.push(context,
|
||||
MaterialPageRoute(builder: (_) => SessionScreen(session: full)));
|
||||
// The full session, not the copy limited to one format
|
||||
Session _full(Session session) => _sessions!
|
||||
.firstWhere((s) => s.name == session.name, orElse: () => session);
|
||||
|
||||
Future<void> _openDetails(Session session) async {
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => SessionScreen(session: _full(session))));
|
||||
_load();
|
||||
}
|
||||
|
||||
@@ -188,7 +192,7 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
);
|
||||
}
|
||||
|
||||
// Filters continue the dark app bar, like Koledar/Stiki; sort toggle at the end
|
||||
// Filters continue the dark app bar, like Koledar/Stiki
|
||||
Widget _buildTabs() {
|
||||
final s = AppSettings.instance;
|
||||
return BarTabs(
|
||||
@@ -201,19 +205,18 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
_filter = _Filter.values[i];
|
||||
_shots = null;
|
||||
}),
|
||||
trailing: IconButton(
|
||||
tooltip: _sortByScore ? s.t('Sort by Score') : s.t('Sort by Date'),
|
||||
icon: Icon(
|
||||
_sortByScore ? Icons.leaderboard_rounded : Icons.event_rounded,
|
||||
color: Colors.white),
|
||||
onPressed: () => setState(() => _sortByScore = !_sortByScore),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Second dark row under the tabs: shots-per-target pills left, year right
|
||||
// Always 1–5 (the capture limit); older saves above 5 keep their own pill.
|
||||
// Formats with no targets yet are dimmed and can't be picked.
|
||||
Widget _buildFilterBar(List<int> formats, int? selected) {
|
||||
final sorted = [...formats]..sort();
|
||||
final sorted = {
|
||||
for (int n = AppSettings.minBullets; n <= AppSettings.maxBullets; n++) n,
|
||||
...formats,
|
||||
}.toList()
|
||||
..sort();
|
||||
return Container(
|
||||
color: AppTheme.bar,
|
||||
padding: const EdgeInsets.fromLTRB(12, 0, 4, 8),
|
||||
@@ -224,11 +227,18 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
Text(AppSettings.instance.t('Shots'),
|
||||
style:
|
||||
const TextStyle(fontSize: 12, color: Colors.white60)),
|
||||
const SizedBox(width: 8),
|
||||
for (final n in sorted) ...[
|
||||
_BarPill(
|
||||
label: shotCount(n),
|
||||
label: '$n',
|
||||
selected: n == selected,
|
||||
onTap: () => setState(() => _shots = n)),
|
||||
empty: !formats.contains(n),
|
||||
onTap: formats.contains(n)
|
||||
? () => setState(() => _shots = n)
|
||||
: null),
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
],
|
||||
@@ -286,15 +296,7 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
.toList()
|
||||
.reversed
|
||||
.toList(); // oldest first
|
||||
|
||||
// Last session's average per shot compared with the overall average
|
||||
final last =
|
||||
chartSessions.isNotEmpty ? chartSessions.last.averagePerShot : null;
|
||||
final delta = (last != null &&
|
||||
stats.averagePerShot != null &&
|
||||
chartSessions.length > 1)
|
||||
? last - stats.averagePerShot!
|
||||
: null;
|
||||
const divider = VerticalDivider(width: 1, color: Colors.white24);
|
||||
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
@@ -303,77 +305,56 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Dark header: headline number left, trend right
|
||||
// Dark header: all four numbers in equal columns
|
||||
Container(
|
||||
color: AppTheme.bar,
|
||||
padding: const EdgeInsets.fromLTRB(20, 14, 16, 14),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(s.t('Average per shot'),
|
||||
style: const TextStyle(
|
||||
fontSize: 13, color: Colors.white60)),
|
||||
Text(
|
||||
stats.averagePerShot?.toStringAsFixed(2) ?? '–',
|
||||
style: const TextStyle(
|
||||
fontSize: 40,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: Colors.white,
|
||||
height: 1.15),
|
||||
),
|
||||
],
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 14),
|
||||
child: IntrinsicHeight(
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _MiniStat(
|
||||
label: s.t('Average per shot'),
|
||||
value: stats.averagePerShot?.toStringAsFixed(2) ?? '–',
|
||||
),
|
||||
),
|
||||
),
|
||||
if (delta != null)
|
||||
_TrendBadge(delta: delta, label: s.t('last training')),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (chartSessions.length > 1) ...[
|
||||
const SizedBox(height: 4),
|
||||
ProgressChart(
|
||||
points: _chartPoints(chartSessions),
|
||||
color: s.bulletColor,
|
||||
textColor: surf.textSecondary,
|
||||
gridColor: surf.divider,
|
||||
divider,
|
||||
Expanded(
|
||||
child: _MiniStat(
|
||||
label: s.t('Best target'),
|
||||
value: '${stats.best!.score}',
|
||||
),
|
||||
),
|
||||
divider,
|
||||
Expanded(
|
||||
child: _MiniStat(
|
||||
label: s.t('Average target'),
|
||||
value: stats.averageTarget!.toStringAsFixed(1),
|
||||
),
|
||||
),
|
||||
divider,
|
||||
Expanded(
|
||||
child: _MiniStat(
|
||||
label: s.t(_filter == _Filter.tournament
|
||||
? 'Tournaments'
|
||||
: 'Trainings'),
|
||||
value: '${stats.sessions}',
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
Divider(height: 1, color: surf.divider),
|
||||
const SizedBox(height: 14),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _MiniStat(
|
||||
label: s.t('Best target'),
|
||||
value: '${stats.best!.score}',
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: _MiniStat(
|
||||
label: s.t('Average target'),
|
||||
value: stats.averageTarget!.toStringAsFixed(1),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: _MiniStat(
|
||||
label: s.t('Targets'),
|
||||
value: '${stats.targets}',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (chartSessions.length > 1)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 12),
|
||||
child: ProgressChart(
|
||||
points: _chartPoints(chartSessions),
|
||||
color: s.bulletColor,
|
||||
textColor: surf.textSecondary,
|
||||
gridColor: surf.divider,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -385,25 +366,29 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
final surf = Surfaces.current;
|
||||
final widgets = <Widget>[];
|
||||
|
||||
String monthOf(Session x) =>
|
||||
DateFormat('LLLL yyyy', _locale).format(x.date).toUpperCase();
|
||||
|
||||
if (_sortByScore) {
|
||||
final ranked = [...sessions]
|
||||
..sort((a, b) => b.totalScore.compareTo(a.totalScore));
|
||||
widgets.add(_monthHeader(s.t('Best results')));
|
||||
// Average per shot, so sessions with more targets don't win by volume
|
||||
final ranked = [...sessions]..sort(
|
||||
(a, b) => (b.averagePerShot ?? 0).compareTo(a.averagePerShot ?? 0));
|
||||
widgets.add(_sortBar(s.t('Best results').toUpperCase()));
|
||||
widgets.addAll(ranked.map(_sessionCard));
|
||||
return widgets;
|
||||
}
|
||||
|
||||
String? month;
|
||||
for (final session in sessions) {
|
||||
final m =
|
||||
DateFormat('LLLL yyyy', _locale).format(session.date).toUpperCase();
|
||||
final m = monthOf(session);
|
||||
if (m != month) {
|
||||
widgets.add(_monthHeader(m));
|
||||
// The first month header shares its row with the sort toggle
|
||||
widgets.add(month == null ? _sortBar(m) : _monthHeader(m));
|
||||
month = m;
|
||||
}
|
||||
widgets.add(_sessionCard(session));
|
||||
}
|
||||
if (widgets.isEmpty) {
|
||||
if (sessions.isEmpty) {
|
||||
widgets.add(Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Text(s.t('No saved target data found'),
|
||||
@@ -413,6 +398,53 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
return widgets;
|
||||
}
|
||||
|
||||
// Sort choice sits right above the list it sorts
|
||||
Widget _sortBar(String title) {
|
||||
final s = AppSettings.instance;
|
||||
final surf = Surfaces.current;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(4, 16, 0, 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 1.4,
|
||||
color: surf.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
SegmentedButton<bool>(
|
||||
showSelectedIcon: false,
|
||||
style: SegmentedButton.styleFrom(
|
||||
visualDensity: VisualDensity.compact,
|
||||
selectedBackgroundColor: s.bulletColor,
|
||||
selectedForegroundColor: Colors.white,
|
||||
foregroundColor: surf.textSecondary,
|
||||
textStyle:
|
||||
const TextStyle(fontSize: 12, fontWeight: FontWeight.w600),
|
||||
),
|
||||
segments: [
|
||||
ButtonSegment(
|
||||
value: false,
|
||||
icon: const Icon(Icons.event_rounded, size: 16),
|
||||
label: Text(s.t('Sort by Date'))),
|
||||
ButtonSegment(
|
||||
value: true,
|
||||
icon: const Icon(Icons.leaderboard_rounded, size: 16),
|
||||
label: Text(s.t('Sort by Score'))),
|
||||
],
|
||||
selected: {_sortByScore},
|
||||
onSelectionChanged: (v) => setState(() => _sortByScore = v.first),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _monthHeader(String text) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(4, 24, 4, 10),
|
||||
@@ -428,14 +460,12 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
);
|
||||
}
|
||||
|
||||
// Same build as the calendar cards: date block on the left, content in the
|
||||
// middle (opens the training), action strip on the right (opens all targets).
|
||||
// Date block on the left like the calendar cards. Tap shows this session's
|
||||
// targets of the selected format on one target; the menu opens details/edit.
|
||||
Widget _sessionCard(Session session) {
|
||||
final s = AppSettings.instance;
|
||||
final surf = Surfaces.current;
|
||||
final avg = session.averagePerShot;
|
||||
final full = _sessions!
|
||||
.firstWhere((x) => x.name == session.name, orElse: () => session);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
@@ -461,9 +491,10 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => _openSession(session),
|
||||
onTap: () => _openTargets(session),
|
||||
onLongPress: () => _openDetails(session),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 12, 12, 12),
|
||||
padding: const EdgeInsets.fromLTRB(14, 12, 4, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
@@ -516,16 +547,10 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
),
|
||||
),
|
||||
),
|
||||
Material(
|
||||
color: AppTheme.bar,
|
||||
child: InkWell(
|
||||
onTap: () => _openAllTargets(full),
|
||||
child: const SizedBox(
|
||||
width: 56,
|
||||
child: Icon(Icons.visibility_rounded,
|
||||
color: Colors.white, size: 22),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: s.t('Details'),
|
||||
icon: Icon(Icons.more_vert_rounded, color: surf.textSecondary),
|
||||
onPressed: () => _openDetails(session),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -534,7 +559,7 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _openAllTargets(Session session) async {
|
||||
Future<void> _openTargets(Session session) async {
|
||||
if (session.targets.isEmpty) return;
|
||||
await Navigator.push(
|
||||
context,
|
||||
@@ -580,50 +605,39 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
||||
}
|
||||
}
|
||||
|
||||
/// ▲/▼ difference with an icon, so the direction never depends on color alone.
|
||||
class _TrendBadge extends StatelessWidget {
|
||||
final double delta;
|
||||
final String label;
|
||||
|
||||
const _TrendBadge({required this.delta, required this.label});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final up = delta >= 0;
|
||||
final color = up ? Colors.green[700]! : Colors.red[700]!;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: color, borderRadius: BorderRadius.circular(12)),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
up
|
||||
? Icons.arrow_upward_rounded
|
||||
: Icons.arrow_downward_rounded,
|
||||
size: 14,
|
||||
color: Colors.white),
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
delta.abs().toStringAsFixed(2),
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(label,
|
||||
style: const TextStyle(fontSize: 11, color: Colors.white60)),
|
||||
],
|
||||
);
|
||||
}
|
||||
/// What Knjiga shows and where to tap; opened from the info button in the app bar.
|
||||
void showBookHelp(BuildContext context) {
|
||||
final s = AppSettings.instance;
|
||||
showHelpSheet(context, accent: s.bulletColor, t: s.t, items: const [
|
||||
(
|
||||
Icons.emoji_events_rounded,
|
||||
'Trainings / Tournaments: choose which sessions the statistics count.'
|
||||
),
|
||||
(
|
||||
Icons.filter_5_rounded,
|
||||
'Shots 1–5: statistics only compare targets with the same number of shots. Grey numbers have no targets yet.'
|
||||
),
|
||||
(
|
||||
Icons.calendar_month_rounded,
|
||||
'Year (top right): choose which year to show.'
|
||||
),
|
||||
(
|
||||
Icons.show_chart_rounded,
|
||||
'Graph: average per shot over time. Tap or drag on it to see each value.'
|
||||
),
|
||||
(
|
||||
Icons.leaderboard_rounded,
|
||||
'By date / By score: sort the list by date or by best average per shot.'
|
||||
),
|
||||
(
|
||||
Icons.touch_app_rounded,
|
||||
'Tap a session to see all its targets with the selected number of shots on one target.'
|
||||
),
|
||||
(
|
||||
Icons.more_vert_rounded,
|
||||
'Three dots on the right or long press: session details, single targets, rename and delete.'
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
class _MiniStat extends StatelessWidget {
|
||||
@@ -632,19 +646,27 @@ class _MiniStat extends StatelessWidget {
|
||||
|
||||
const _MiniStat({required this.label, required this.value});
|
||||
|
||||
// White on the dark header; labels get two lines since four share the width
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final surf = Surfaces.current;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(value,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: surf.textPrimary)),
|
||||
Text(label, style: TextStyle(fontSize: 12, color: surf.textSecondary)),
|
||||
],
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(value,
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: Colors.white)),
|
||||
const SizedBox(height: 2),
|
||||
Text(label,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 11, color: Colors.white60, height: 1.2)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -697,10 +719,14 @@ class _DateBlock extends StatelessWidget {
|
||||
class _BarPill extends StatelessWidget {
|
||||
final String label;
|
||||
final bool selected;
|
||||
final VoidCallback onTap;
|
||||
final bool empty; // no targets with this many shots
|
||||
final VoidCallback? onTap; // null = not selectable
|
||||
|
||||
const _BarPill(
|
||||
{required this.label, required this.selected, required this.onTap});
|
||||
{required this.label,
|
||||
required this.selected,
|
||||
this.empty = false,
|
||||
required this.onTap});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -712,13 +738,15 @@ class _BarPill extends StatelessWidget {
|
||||
customBorder: const StadiumBorder(),
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: selected ? Colors.black : Colors.white70,
|
||||
color: selected
|
||||
? Colors.black
|
||||
: (empty ? Colors.white30 : Colors.white70),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user