calendar fix and update.

This commit is contained in:
2026-10-25 17:46:55 +01:00
parent cd3398df99
commit 9a65ff7ad4
10 changed files with 2596 additions and 1651 deletions
+17 -20
View File
@@ -29,6 +29,7 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
List<Offset> _bullets = [];
List<Offset> _scaledBullets = []; // Bullets scaled to display target size
int _totalScore = 0;
Map<int, int> _folderChartScores = {};
Offset? _targetCenter;
Uint8List? _targetImageBytes;
img.Image? _targetImageDecoded;
@@ -256,6 +257,21 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
.map((b) => _scoreForBullet(b, _targetCenter!))
.fold(0, (sum, score) => sum + score);
// Pre-compute folder chart scores to avoid sync file reads in build
if (widget.isCombinedView) {
final chartScores = <int, int>{};
for (int i = 0; i < widget.jsonFiles.length; i++) {
final data = jsonDecode(await widget.jsonFiles[i].readAsString());
final bullets = (data['bullets'] as List?) ?? [];
int s = 0;
for (final b in bullets) {
s += _scoreForBullet(Offset(b['x'].toDouble(), b['y'].toDouble()), _targetCenter!);
}
chartScores[i + 1] = s;
}
_folderChartScores = chartScores;
}
setState(() {});
} catch (e) {
print("Error loading JSON or image: $e");
@@ -565,26 +581,7 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
}
Widget _buildFolderChartView() {
// Calculate target scores from all files
// Each file represents one target at position (fileIndex + 1)
final Map<int, int> targetScores = {};
for (int fileIdx = 0; fileIdx < widget.jsonFiles.length; fileIdx++) {
final file = widget.jsonFiles[fileIdx];
final targetPosition = fileIdx + 1; // T1, T2, T3, etc.
final data = jsonDecode(file.readAsStringSync());
final bullets = (data['bullets'] as List?) ?? [];
// Sum scores for this target
int targetScore = 0;
for (int j = 0; j < bullets.length; j++) {
final bullet = Offset(bullets[j]['x'].toDouble(), bullets[j]['y'].toDouble());
final score = _scoreForBullet(bullet, _targetCenter ?? Offset.zero);
targetScore += score;
}
targetScores[targetPosition] = targetScore;
}
final Map<int, int> targetScores = _folderChartScores;
if (targetScores.isEmpty) {
return Center(