This commit is contained in:
2025-10-16 17:42:46 +02:00
parent dc86955721
commit 2e3a69a23e
12 changed files with 1421 additions and 604 deletions
+69 -18
View File
@@ -5,6 +5,7 @@ import 'package:flutter/services.dart' show rootBundle;
import 'dart:convert';
import 'package:image/image.dart' as img;
import 'package:shared_preferences/shared_preferences.dart';
import '../utils/translations.dart';
class TargetViewScreen extends StatefulWidget {
final List<File> jsonFiles;
@@ -38,15 +39,28 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
final double bulletSize = 19;
Color _bulletColor = Colors.blue; // default/fallback bullet color
String _selectedLanguage = 'English';
@override
void initState() {
super.initState();
_loadBulletColor();
_loadBulletColor();
_loadLanguage();
_loadJsonAndImage();
}
String _t(String key) {
return AppTranslations.translate(key, _selectedLanguage);
}
Future<void> _loadLanguage() async {
final prefs = await SharedPreferences.getInstance();
setState(() {
_selectedLanguage = prefs.getString('language') ?? 'English';
});
}
Future<void> _loadBulletColor() async {
final prefs = await SharedPreferences.getInstance();
final selectedColor = prefs.getString('bulletColor') ?? 'Blue';
@@ -116,7 +130,25 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
final jsonString = await currentFile.readAsString();
final data = jsonDecode(jsonString);
_date = data['date'] ?? 'Unknown Date';
// Parse and convert date format from yyyy-m-d to dd/MM/yyyy
String rawDate = data['date'] ?? 'Unknown Date';
if (rawDate != 'Unknown Date' && rawDate.contains('-')) {
try {
final parts = rawDate.split('-');
if (parts.length == 3) {
final year = parts[0];
final month = parts[1].padLeft(2, '0');
final day = parts[2].padLeft(2, '0');
_date = '$day/$month/$year';
} else {
_date = rawDate;
}
} catch (e) {
_date = rawDate;
}
} else {
_date = rawDate;
}
final bulletsJson = data['bullets'] as List;
_bullets = bulletsJson.map((b) => Offset(b['x'], b['y'])).toList();
@@ -185,9 +217,9 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text(
'Delete Target',
style: TextStyle(
Text(
_t('Delete Target'),
style: const TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
@@ -195,9 +227,9 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
const Text(
"Are you sure you want to delete this target?",
style: TextStyle(color: Colors.white70, fontSize: 16),
Text(
_t("Are you sure you want to delete this target?"),
style: const TextStyle(color: Colors.white70, fontSize: 16),
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
@@ -218,7 +250,7 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
borderRadius: BorderRadius.circular(12),
),
),
child: const Text("Yes, delete"),
child: Text(_t("Yes, delete")),
),
),
const SizedBox(height: 12),
@@ -339,17 +371,36 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
),
bottomNavigationBar: BottomAppBar(
color: Colors.grey[900],
padding: EdgeInsets.zero,
child: SizedBox(
height: 56,
child: Center(
child: Text(
"🎯 Total Score: $_totalScore",
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: Colors.white,
height: 150,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Combined badge with text and score
Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
decoration: BoxDecoration(
color: Colors.grey[800],
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: Colors.grey[700]!,
width: 2,
),
),
child: FittedBox(
fit: BoxFit.scaleDown,
child: Text(
"🎯 ${_t('Total score')} $_totalScore",
style: const TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
),
],
),
),
),