new UI + new targets.

This commit is contained in:
Jan Pleterski
2026-11-27 14:37:44 +01:00
parent 5f9e2a3b86
commit 2fc741a9f6
113 changed files with 6861 additions and 7381 deletions
+141 -242
View File
@@ -1,45 +1,41 @@
import 'dart:io';
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:path_provider/path_provider.dart';
import 'package:share_plus/share_plus.dart';
import '../screens/target_view.dart' show BarChartPainter;
import '../models/target_style.dart';
import '../theme/app_theme.dart';
import '../utils/format.dart';
import 'bar_list.dart';
import 'target_face.dart';
import 'ui.dart';
/// Everything the share image shows, taken from the target view as it is.
/// Everything the share image shows, taken from the result screen as it is.
class ResultShareData {
final String title; // session (folder) name
final String date; // already formatted, e.g. 12.11.2026
final String countsLine; // e.g. "7 tarč · 35 strelov"
final String title; // "Trening 18" or "Tarča 3"
final String subtitle; // date, counts
final int total;
final double? averagePerShot;
final Uint8List targetImage; // the selected target design
final Size targetImageSize;
final List<Offset> bullets; // in targetImage pixels
final double bulletDiameter; // in targetImage pixels
final Color bulletColor;
final Color targetBackground; // matches the target design
final List<(String top, String bottom)> tiles; // e.g. ("6x", "10")
final List<MapEntry<int, int>> chart; // bar label number -> points
final bool chartPerShot; // bars are shots of one target, not targets of a session
final TargetStyle style;
final List<Offset> hits; // in target space
final List<(String? top, String value, bool filled)> tiles;
final String chartTitle;
final List<BarEntry> bars;
final double barMax;
final String Function(String) t;
const ResultShareData({
required this.title,
required this.date,
required this.countsLine,
required this.subtitle,
required this.total,
required this.averagePerShot,
required this.targetImage,
required this.targetImageSize,
required this.bullets,
required this.bulletDiameter,
required this.bulletColor,
required this.targetBackground,
required this.style,
required this.hits,
required this.tiles,
required this.chart,
required this.chartPerShot,
required this.chartTitle,
required this.bars,
required this.barMax,
required this.t,
});
}
@@ -56,7 +52,8 @@ Future<void> shareResult(BuildContext context, ResultShareData data) async {
OverlayEntry? entry;
try {
// Decode the target first so it is in the very first frame
await precacheImage(MemoryImage(data.targetImage), context);
final asset = data.style.asset;
if (asset != null) await precacheImage(AssetImage(asset), context);
// Laid out and painted, but outside the screen
entry = OverlayEntry(
@@ -81,8 +78,7 @@ Future<void> shareResult(BuildContext context, ResultShareData data) async {
entry = null;
final dir = await getTemporaryDirectory();
final file = File(
'${dir.path}/sdk_kovinar_${DateTime.now().millisecondsSinceEpoch}.png');
final file = File('${dir.path}/sdk_kovinar_${DateTime.now().millisecondsSinceEpoch}.png');
await file.writeAsBytes(png!.buffer.asUint8List());
await SharePlus.instance.share(ShareParams(
files: [XFile(file.path, mimeType: 'image/png')],
@@ -97,8 +93,8 @@ Future<void> shareResult(BuildContext context, ResultShareData data) async {
}
}
/// The 960x540 image: header with the result, target with score tiles on the
/// left, the bar chart with every value on the right.
/// The 960×540 image: the result in the header, the target with its tiles on
/// the left, the bar chart with every value on the right.
class ResultShareCard extends StatelessWidget {
static const Size size = Size(960, 540);
final ResultShareData data;
@@ -106,256 +102,159 @@ class ResultShareCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
final c = Palette.current;
final t = data.t;
final accent = data.bulletColor;
return SizedBox.fromSize(
size: size,
child: Material(
color: const Color(0xFF1B1E21),
child: Padding(
padding: const EdgeInsets.fromLTRB(28, 22, 28, 22),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Header
Row(
crossAxisAlignment: CrossAxisAlignment.end,
color: c.bg,
child: Stack(
children: [
// Faint rings behind the header, like a target in the corner
Positioned(
right: -260,
top: -330,
child: CustomPaint(size: const Size(700, 700), painter: _Rings(c.line2)),
),
Padding(
padding: const EdgeInsets.fromLTRB(32, 26, 32, 32),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('SD KOVINAR',
style: TextStyle(
color: accent,
fontSize: 12,
fontWeight: FontWeight.w800,
letterSpacing: 2.5)),
const SizedBox(height: 2),
Text(data.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: Colors.white,
fontSize: 28,
fontWeight: FontWeight.w800)),
const SizedBox(height: 2),
Text('${data.date} · ${data.countsLine}',
style: const TextStyle(
color: Colors.white60, fontSize: 14)),
],
),
),
if (data.averagePerShot != null)
_HeaderFigure(
label: t('Average per shot'),
value: data.averagePerShot!.toStringAsFixed(2),
size: 40),
const SizedBox(width: 28),
_HeaderFigure(
label: t('Total score').replaceAll(':', ''),
value: '${data.total}',
size: 40,
color: accent),
],
),
const SizedBox(height: 16),
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Target and score tiles
Container(
width: 380,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: data.targetBackground,
borderRadius: BorderRadius.circular(18),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('SD KOVINAR MUTA',
style: TextStyle(color: c.accent, fontSize: 12, fontWeight: FontWeight.w800, letterSpacing: 2.2)),
const SizedBox(height: 4),
Text(data.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: c.ink, fontSize: 30, fontWeight: FontWeight.w700, height: 1.15)),
const SizedBox(height: 4),
Text(data.subtitle, style: TextStyle(color: c.muted, fontSize: 14)),
],
),
),
child: Column(
children: [
Expanded(
child: Center(
child: AspectRatio(
aspectRatio: data.targetImageSize.width /
data.targetImageSize.height,
child: _TargetWithHits(data: data),
),
),
),
const SizedBox(height: 10),
SizedBox(
height: 58,
child: Row(
if (data.averagePerShot != null)
_HeaderFigure(label: t('Average per shot'), value: dec(data.averagePerShot!), color: c.ink),
const SizedBox(width: 40),
_HeaderFigure(label: t('Total'), value: '${data.total}', color: c.accent),
],
),
const SizedBox(height: 20),
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SizedBox(
width: 400,
child: AppCard(
padding: const EdgeInsets.fromLTRB(14, 10, 14, 14),
child: Column(
children: [
for (final (top, bottom) in data.tiles)
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 3),
child: _Tile(
top: top,
bottom: bottom,
color: accent),
),
Expanded(
child: Center(
child: TargetFace(style: data.style, hits: data.hits, hitColor: c.accent),
),
),
const SizedBox(height: 10),
Row(
children: [
for (int i = 0; i < data.tiles.length; i++) ...[
if (i > 0) const SizedBox(width: 6),
Expanded(
child: ScoreTile(
top: data.tiles[i].$1,
value: data.tiles[i].$2,
filled: data.tiles[i].$3,
height: 60,
),
),
],
],
),
],
),
),
],
),
),
const SizedBox(width: 16),
// Chart with every value
Expanded(
child: Container(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 4),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(18),
),
child: CustomPaint(
size: Size.infinite,
painter: BarChartPainter(
data: data.chart,
maxScore: _chartMax(data),
bulletColor: accent,
isShotView: data.chartPerShot,
backgroundColor: Colors.white,
translateFunc: t,
xAxisLabelKey: data.chartPerShot ? 'Points' : null,
const SizedBox(width: 20),
Expanded(
child: AppCard(
padding: const EdgeInsets.fromLTRB(20, 20, 20, 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Kicker(data.chartTitle, padding: const EdgeInsets.only(bottom: 14)),
Expanded(
child: BarList(
entries: data.bars,
max: data.barMax,
ticks: [0, data.barMax / 2, data.barMax],
labelWidth: 36,
valueWidth: 56,
scale: 1.1,
),
),
],
),
),
),
),
],
),
],
),
),
],
),
],
),
),
],
),
),
);
}
}
static double _chartMax(ResultShareData d) {
final max = d.chart.isEmpty
? 0
: d.chart.map((e) => e.value).reduce((a, b) => a > b ? a : b);
return max <= 0 ? 1 : max.toDouble();
class _Rings extends CustomPainter {
final Color color;
const _Rings(this.color);
@override
void paint(Canvas canvas, Size size) {
final p = Paint()
..style = PaintingStyle.stroke
..strokeWidth = 1.5
..color = color;
for (double r = 80; r < size.width / 2; r += 55) {
canvas.drawCircle(size.center(Offset.zero), r, p);
}
}
@override
bool shouldRepaint(_Rings old) => old.color != color;
}
class _HeaderFigure extends StatelessWidget {
final String label;
final String value;
final double size;
final Color color;
const _HeaderFigure(
{required this.label,
required this.value,
required this.size,
this.color = Colors.white});
const _HeaderFigure({required this.label, required this.value, required this.color});
@override
Widget build(BuildContext context) {
final c = Palette.current;
return Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Text(label.toUpperCase(),
style: const TextStyle(
color: Colors.white54,
fontSize: 11,
fontWeight: FontWeight.w700,
letterSpacing: 1.5)),
Text(label.toUpperCase(), style: AppTheme.kicker(c).copyWith(letterSpacing: 1.5)),
const SizedBox(height: 4),
Text(value,
style: TextStyle(
color: color,
fontSize: size,
height: 1.05,
fontWeight: FontWeight.w800,
fontFeatures: const [FontFeature.tabularFigures()])),
color: color, fontSize: 44, height: 1.05, fontWeight: FontWeight.w800, fontFeatures: AppTheme.tnum)),
],
);
}
}
class _TargetWithHits extends StatelessWidget {
final ResultShareData data;
const _TargetWithHits({required this.data});
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, c) {
final scale = c.maxWidth / data.targetImageSize.width;
final d = data.bulletDiameter * scale;
return Stack(
children: [
Positioned.fill(
child: Image.memory(data.targetImage,
fit: BoxFit.fill, gaplessPlayback: true)),
for (final b in data.bullets)
Positioned(
left: b.dx * scale - d / 2,
top: b.dy * scale - d / 2,
width: d,
height: d,
child: DecoratedBox(
decoration: BoxDecoration(
color: data.bulletColor.withValues(alpha: 0.85),
shape: BoxShape.circle,
border: Border.all(color: Colors.black, width: 1),
),
),
),
],
);
});
}
}
class _Tile extends StatelessWidget {
final String top;
final String bottom;
final Color color;
const _Tile({required this.top, required this.bottom, required this.color});
@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Column(
children: [
Container(
height: 20,
width: double.infinity,
color: const Color(0xFF2C2F33),
alignment: Alignment.center,
child: FittedBox(
child: Text(top,
style: const TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w700)),
),
),
Expanded(
child: Container(
width: double.infinity,
color: color.withValues(alpha: 0.9),
alignment: Alignment.center,
child: FittedBox(
child: Text(bottom,
style: const TextStyle(
color: Colors.white,
fontSize: 22,
fontWeight: FontWeight.w800)),
),
),
),
],
),
);
}
}