google preperation 1
This commit is contained in:
@@ -43,3 +43,6 @@ app.*.map.json
|
|||||||
/android/app/debug
|
/android/app/debug
|
||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/android/app/release
|
||||||
|
|
||||||
|
# Plain club data (contacts) — encrypted into assets/club.enc, never commit
|
||||||
|
/tool/club_data.json
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import java.util.Properties
|
||||||
|
import java.io.FileInputStream
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.application")
|
id("com.android.application")
|
||||||
id("kotlin-android")
|
id("kotlin-android")
|
||||||
@@ -5,8 +8,15 @@ plugins {
|
|||||||
id("dev.flutter.flutter-gradle-plugin")
|
id("dev.flutter.flutter-gradle-plugin")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Upload key for Google Play. android/key.properties is gitignored — never commit it.
|
||||||
|
val keystoreProperties = Properties()
|
||||||
|
val keystorePropertiesFile = rootProject.file("key.properties")
|
||||||
|
if (keystorePropertiesFile.exists()) {
|
||||||
|
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
|
||||||
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "com.example.shooter_app"
|
namespace = "si.sdkkovinar.app"
|
||||||
compileSdk = flutter.compileSdkVersion
|
compileSdk = flutter.compileSdkVersion
|
||||||
|
|
||||||
ndkVersion = "27.0.12077973" // ✅ Keep only this line
|
ndkVersion = "27.0.12077973" // ✅ Keep only this line
|
||||||
@@ -22,16 +32,32 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "com.example.shooter_app"
|
applicationId = "si.sdkkovinar.app"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 33
|
targetSdk = 36
|
||||||
versionCode = flutter.versionCode
|
versionCode = flutter.versionCode
|
||||||
versionName = flutter.versionName
|
versionName = flutter.versionName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signingConfigs {
|
||||||
|
create("release") {
|
||||||
|
if (keystorePropertiesFile.exists()) {
|
||||||
|
keyAlias = keystoreProperties["keyAlias"] as String
|
||||||
|
keyPassword = keystoreProperties["keyPassword"] as String
|
||||||
|
storeFile = file(keystoreProperties["storeFile"] as String)
|
||||||
|
storePassword = keystoreProperties["storePassword"] as String
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
signingConfig = signingConfigs.getByName("debug")
|
// Falls back to debug key only when key.properties is missing (local testing).
|
||||||
|
signingConfig = if (keystorePropertiesFile.exists()) {
|
||||||
|
signingConfigs.getByName("release")
|
||||||
|
} else {
|
||||||
|
signingConfigs.getByName("debug")
|
||||||
|
}
|
||||||
isMinifyEnabled = false
|
isMinifyEnabled = false
|
||||||
isShrinkResources = false
|
isShrinkResources = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,14 +11,13 @@
|
|||||||
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:label="SDK Muta"
|
android:label="SDK Kovinar"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
android:enableOnBackInvokedCallback="true"
|
android:enableOnBackInvokedCallback="true"
|
||||||
android:usesCleartextTraffic="true"
|
android:usesCleartextTraffic="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:requestLegacyExternalStorage="true"
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
android:preserveLegacyExternalStorage="true"
|
android:localeConfig="@xml/locales_config">
|
||||||
android:networkSecurityConfig="@xml/network_security_config">
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.example.shooter_app
|
|
||||||
|
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
|
||||||
|
|
||||||
class MainActivity : FlutterActivity()
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.example.test1
|
|
||||||
|
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
|
||||||
|
|
||||||
class MainActivity : FlutterActivity()
|
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package si.sdkkovinar.app
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.Network
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
|
import android.net.NetworkRequest
|
||||||
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
|
import io.flutter.plugin.common.MethodChannel
|
||||||
|
|
||||||
|
class MainActivity : FlutterActivity() {
|
||||||
|
private val connectivity by lazy {
|
||||||
|
getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
}
|
||||||
|
private var wifiCallback: ConnectivityManager.NetworkCallback? = null
|
||||||
|
|
||||||
|
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||||
|
super.configureFlutterEngine(flutterEngine)
|
||||||
|
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "si.sdkkovinar.app/network")
|
||||||
|
.setMethodCallHandler { call, result ->
|
||||||
|
when (call.method) {
|
||||||
|
"bindToWifi" -> result.success(bindToWifi())
|
||||||
|
"unbind" -> {
|
||||||
|
unbind()
|
||||||
|
result.success(null)
|
||||||
|
}
|
||||||
|
else -> result.notImplemented()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The range Wi-Fi has no internet, so Android routes traffic over mobile data
|
||||||
|
// and the cameras' local IPs become unreachable. Pin this app's traffic to
|
||||||
|
// Wi-Fi (other apps keep using mobile data). Returns true if bound right away.
|
||||||
|
private fun bindToWifi(): Boolean {
|
||||||
|
if (wifiCallback == null) {
|
||||||
|
val request = NetworkRequest.Builder()
|
||||||
|
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
|
||||||
|
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||||
|
.build()
|
||||||
|
val callback = object : ConnectivityManager.NetworkCallback() {
|
||||||
|
override fun onAvailable(network: Network) {
|
||||||
|
connectivity.bindProcessToNetwork(network)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLost(network: Network) {
|
||||||
|
if (connectivity.boundNetworkForProcess == network) {
|
||||||
|
connectivity.bindProcessToNetwork(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connectivity.registerNetworkCallback(request, callback)
|
||||||
|
wifiCallback = callback
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
val wifi = connectivity.allNetworks.firstOrNull {
|
||||||
|
connectivity.getNetworkCapabilities(it)
|
||||||
|
?.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) == true
|
||||||
|
} ?: return false
|
||||||
|
return connectivity.bindProcessToNetwork(wifi)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun unbind() {
|
||||||
|
wifiCallback?.let { connectivity.unregisterNetworkCallback(it) }
|
||||||
|
wifiCallback = null
|
||||||
|
connectivity.bindProcessToNetwork(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
unbind()
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Languages offered in Android 13+ Settings > Apps > SDK Kovinar > Language -->
|
||||||
|
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<locale android:name="sl"/>
|
||||||
|
<locale android:name="en"/>
|
||||||
|
</locale-config>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"v":1,"salt":"Mrvt+SH25mgmeHSMLSa5MQ==","nonce":"jeM7rMRlbYVFBf/f","cipher":"fjQ0MEjR5SaCvelQ0v3bMMr9s0YbGjTOjFBrFGMVf2f4gsq4fCVlgqFub9nXcsPHIMxwDTr/GXDWRuJQ1afut0XQl9b1jMLrVgL6ELH2mFpIRcyBFCNSgKeyTLOBFbtPvE1zHcBK3HkJtK8vqdjH/3uzf9sWIIBnOi4bzFz6NbBTzLEIU6LkfKOLOTsXx43GpD1EA8j+5F9LFp4FJq4Ap0A5PHxf4IcTOf41FNaNOnbOKLGbOSXCNuGdLy4IFvSeJ3wnnqaTWJXOOnNOA5oWDr2WCEuEm8PfQuHHxdy5b9SmL5cdTe6W6GyEJrruH+ragADiyi6xC+CCkRA3NgIPgm4VyIB9Tg6M9E02NMg05xpwy8DwPar04QFmAfsfJYD/lAFEpi7ZbcJaHgOj0MLpoOHdJInLndPg6mmwtJm3ov2tdUiLDghGx0VzmWFRn659jng853hQm/7AMJ20pg677hTH9hzamf0jmZkln7NTCvesdnhE4T69sJtP+i89k5L/knH2yEBHkID1p8X0GPp9armxZaozdUTbKTRfykKhCC61rAnJCxjCguPK8+GZexBuaJvMNiGj66z6Z3VFE61Dvv1Q17qrhiMK7ZafH4aeiuFUM9thOmxVR5bgmRtfMAb/RgGFn9QG+qupNyQldediUNlM8HT0sIJDgtMA1Xe8fnZ9+psV/TNgO93KsCNm/GyMl9ksRDg/bU6UqQ+LxELSeHzssPKzLWpVdG1dMgtT2bif/rd2W9YIi+FNUhZWV4Y0wjp0TOfUKrrnM4VyMfYnZ6HrYO4TybW55Ub/gBbVZuXocA7g2pnnBBvk9kL6neeR6Fs5fcIhDZrI66dXvL0YYLe9bpYFjWpo1eQCCTGtCpqdcuxi/SIVWcpJMhVB37Iilw/j7YZHLUSlIfDruNwG4nyoVjM/nTjYp5Akd50kS52pN6JuBbHx7aRQ7iyRd9yGTMY1KDOHJ+QS4A10wkTieaEHOMUFNslfxVWdm+mWGAKFpPJRJNmXOvau4Ees0lGlEo9Rdp1aLe0yCz/PZcMiNJWuGWfibsQP/+Z7Tz0Wrw6XiXpdrcOtF2p3MkBXQTlyJwnXTdz7bspuD3Qb0VU4dULn05PpFP67RQGCTRu0/bxrsRyyoRUXveRWUwT9hQzJHr1uUAGYjMXzNgSi+2/sO6J3KR+CvaKAxh2DiGYnHnG4K2u072jLjLiYiRfnKJCIqLGnpNp2Z4IzhMEYFR03BCyQ0vfA6xBDsGE0esu75kLlOkhJv+Ar5s8pbUK/nkciaRS82p8rXwV86NwV53PqEWMo3veVuQaGdGAVnd3pviJ87eaOXV9dChHdoE7x4nJLTKrxZ1cD28vX1Xdpf9JmNfWMiPTwUCH/pO35x4d47PBMKnOexk18+oBqyJStF9pEiBDATTr1KJBZvIF3qo7NHshh1Ams7N9rg5rp2WqZtm2AAmg56GKRx7GogpdT2MwNNtukDUmnSQ2CqOE2JQzrEVMDZB+MMQd0eb7OaD3FXqpX35ZmI8YDmsSUzEyK4Horil44/bfj3Nwf+LgYKSaAkKjw8rJ5DUU7SUsGFScQXsfmRkp4IHpoR7gHsUX7Abq/9KV35ZYu+hcevR3oaOL5vmIqczPbuJaMVuUgLHna/xmqDZG0jD0kc4tRVNR+LQhzXMWuIsla7KMpXQGng9SyZ0srIBCVZNhNKFH05A7MihUoNbnj2/acEJlg4w22nDqV5up3xHFoj6NX2uJoE+xPfUWqNF+yiIU6qU6TbVJcS1DSa1vKRXYCNsQW9t3jU2F1If8sMEwfDg5iMmSouPnWHBT0LyLI6ypnH4MIAyPjb2tWnEPiDxUuZOO/sq4B81AxV0GIKmVH2baGGVlbl+ZnllumN4TB41SpGTxrMyYUJd5uhu+FA8DyW2oe5y7TQ+L9kS0CiwntRKqvU8lycP057ve2Tg2u1ySw9N5OdVFQLnjei/xx6tEqS8Zd0tItV8OrKQPmQ8NqzTwwqlQ34c92anGk1aP+JTdpMOOsAv6QkbMIQg4uxu2GYfLfAhkYjAzRQ7UV7I9I4OkaSmYTHbRkddR0cGICt4w5+SYhGaZ8CMRdqXZYYo1x1nK/bZakkLcDxiW0zR+oHLHIuORZG9Y6msEPsuVRbdOlOVJVoCYQ/mBEEdqBnzD8RF0J4jGPDuJhN/GkICElzq3WRQjrzbjw17oimhfe/QD6yFi25vttiltP2JF0a38t4mpv5O8IQi02H3/E/8zSV9NvXin1RUXXlRnWdTmKROHbwJC4NnvUUBURggkfVNGnYpfxNs6joQLZOr4tpaHAFBIceBMafjXO5rybu2vFPwBErB+mQMbZ37o8MQKtSZBow587IjrTHfwefixurk2RzL/Z+Gk4BwGOhQzn9HSa5g6051PqBjsBwbLdjVdGhhvEUG0I6hPKKTr6nKRnkLoxBbWM0BnPlHmftxqPVcWSOaan7XSTMUF3mVcs0rILt3McRHx3IKEUoLmxot88Un58dDTjg4RIlWRaxdfzNXQEZDPkvpBbjj1/tSc4jhRTgepd8/0PcpN5uFx04GKlPPuOmjxoDFUQxwbD9EdMASsFy1k7Vk2HgWWOuay/w7PVah1mlFXLh9f6O6Q2bDMtuaasTWUl9bqKSu5IbAvgg58LskFZOOlH60UnTa+oWt4nl1aLW9+h5ZywgyYqoBtIlVA246DaTPQ1gMwPODNJxXV2ectRFUYCUvf6/hwPclQ/r7PZRxoSxeL9iSLeh9Ib6Ca+HbX4+pGL0HYbmJuk","mac":"nCVGDv9Ks7x0MIAUGk3Xvg=="}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 337 KiB |
@@ -0,0 +1,3 @@
|
|||||||
|
description: This file stores settings for Dart & Flutter DevTools.
|
||||||
|
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
|
||||||
|
extensions:
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||||
<key>CFBundleDisplayName</key>
|
<key>CFBundleDisplayName</key>
|
||||||
<string>Shooter App</string>
|
<string>SDK Kovinar</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>$(EXECUTABLE_NAME)</string>
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
|
|||||||
+27
-18
@@ -1,10 +1,15 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart'; // Import for SystemChrome
|
import 'package:flutter/services.dart'; // Import for SystemChrome
|
||||||
|
import 'package:intl/date_symbol_data_local.dart';
|
||||||
import 'screens/home_screen.dart';
|
import 'screens/home_screen.dart';
|
||||||
import 'services/notification_service.dart';
|
import 'services/notification_service.dart';
|
||||||
|
import 'services/app_settings.dart';
|
||||||
|
import 'theme/app_theme.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
await AppSettings.instance.load();
|
||||||
|
await initializeDateFormatting(); // Slovenian month/day names for every screen
|
||||||
try {
|
try {
|
||||||
await NotificationService().initialize();
|
await NotificationService().initialize();
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
@@ -23,43 +28,47 @@ void main() async {
|
|||||||
statusBarColor: Colors.grey[900],
|
statusBarColor: Colors.grey[900],
|
||||||
systemNavigationBarColor: Colors.grey[900],
|
systemNavigationBarColor: Colors.grey[900],
|
||||||
systemNavigationBarIconBrightness: Brightness.light,
|
systemNavigationBarIconBrightness: Brightness.light,
|
||||||
|
// No grey scrim behind 3-button navigation; we paint the strip ourselves
|
||||||
|
systemNavigationBarContrastEnforced: false,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const MyApp({super.key});
|
const MyApp({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'SDK Muta',
|
title: 'SDK Kovinar',
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
theme: ThemeData(
|
theme: AppTheme.light(),
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.white),
|
darkTheme: AppTheme.dark(),
|
||||||
useMaterial3: true,
|
|
||||||
),
|
|
||||||
darkTheme: ThemeData(
|
|
||||||
colorScheme: ColorScheme.fromSeed(
|
|
||||||
seedColor: Colors.blue,
|
|
||||||
brightness: Brightness.dark,
|
|
||||||
),
|
|
||||||
useMaterial3: true,
|
|
||||||
dialogTheme: DialogThemeData(
|
|
||||||
backgroundColor: Colors.grey[900],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
final originalTextScaler = MediaQuery.of(context).textScaler;
|
final originalTextScaler = MediaQuery.of(context).textScaler;
|
||||||
final clampedScale = originalTextScaler.clamp(minScaleFactor: 0.8, maxScaleFactor: 1.2);
|
final clampedScale =
|
||||||
|
originalTextScaler.clamp(minScaleFactor: 0.8, maxScaleFactor: 1.2);
|
||||||
|
// Edge-to-edge (Android 15+) ignores the navigation bar color, so paint
|
||||||
|
// the system bar strip ourselves on every screen, matching our bars.
|
||||||
|
final systemBar = MediaQuery.viewPaddingOf(context).bottom;
|
||||||
return MediaQuery(
|
return MediaQuery(
|
||||||
data: MediaQuery.of(context).copyWith(
|
data: MediaQuery.of(context).copyWith(
|
||||||
textScaler: clampedScale,
|
textScaler: clampedScale,
|
||||||
),
|
),
|
||||||
child: child!,
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
child!,
|
||||||
|
Positioned(
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
height: systemBar,
|
||||||
|
child: IgnorePointer(child: ColoredBox(color: AppTheme.bar)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
home: const HomeScreen(),
|
home: const HomeScreen(),
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/// Which cameras exist: shooting positions (lanes 1–6) × locations (strelišča).
|
||||||
|
/// Each position can have a camera at several locations, e.g. "Kovinar" and "Doma".
|
||||||
|
class CameraSetup {
|
||||||
|
static const int maxPositions = 6;
|
||||||
|
static const int firstPort = 9081;
|
||||||
|
|
||||||
|
final List<String> locations;
|
||||||
|
final int positions;
|
||||||
|
final Map<int, Map<String, String>> ips; // position (1-based) → location → ip:port
|
||||||
|
final String? activeLocation; // last chosen, used by screens that show one location
|
||||||
|
final String? clubLocation; // added by the club code, removed when access is removed
|
||||||
|
|
||||||
|
const CameraSetup({
|
||||||
|
this.locations = const [],
|
||||||
|
this.positions = maxPositions,
|
||||||
|
this.ips = const {},
|
||||||
|
this.activeLocation,
|
||||||
|
this.clubLocation,
|
||||||
|
});
|
||||||
|
|
||||||
|
String ipFor(int position, String location) => ips[position]?[location] ?? '';
|
||||||
|
|
||||||
|
/// Locations with a camera at [position], in the user's location order.
|
||||||
|
Map<String, String> camerasAt(int position) => {
|
||||||
|
for (final l in locations)
|
||||||
|
if (ipFor(position, l).isNotEmpty) l: ipFor(position, l),
|
||||||
|
};
|
||||||
|
|
||||||
|
int camerasIn(String location) => [
|
||||||
|
for (int p = 1; p <= positions; p++)
|
||||||
|
if (ipFor(p, location).isNotEmpty) p,
|
||||||
|
].length;
|
||||||
|
|
||||||
|
CameraSetup copyWith({
|
||||||
|
List<String>? locations,
|
||||||
|
int? positions,
|
||||||
|
Map<int, Map<String, String>>? ips,
|
||||||
|
String? activeLocation,
|
||||||
|
String? clubLocation,
|
||||||
|
bool clearClubLocation = false,
|
||||||
|
}) {
|
||||||
|
return CameraSetup(
|
||||||
|
locations: locations ?? this.locations,
|
||||||
|
positions: positions ?? this.positions,
|
||||||
|
ips: ips ?? this.ips,
|
||||||
|
activeLocation: activeLocation ?? this.activeLocation,
|
||||||
|
clubLocation: clearClubLocation ? null : (clubLocation ?? this.clubLocation),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deep copy of [ips] for editing.
|
||||||
|
Map<int, Map<String, String>> ipsCopy() => {for (final e in ips.entries) e.key: {...e.value}};
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
'locations': locations,
|
||||||
|
'positions': positions,
|
||||||
|
'ips': {for (final e in ips.entries) '${e.key}': e.value},
|
||||||
|
'activeLocation': activeLocation,
|
||||||
|
'clubLocation': clubLocation,
|
||||||
|
};
|
||||||
|
|
||||||
|
factory CameraSetup.fromJson(Map<String, dynamic> json) => CameraSetup(
|
||||||
|
locations: [for (final l in json['locations'] as List? ?? []) l as String],
|
||||||
|
positions: (json['positions'] as int? ?? maxPositions).clamp(1, maxPositions),
|
||||||
|
ips: {
|
||||||
|
for (final e in (json['ips'] as Map<String, dynamic>? ?? {}).entries)
|
||||||
|
int.parse(e.key): {for (final i in (e.value as Map).entries) i.key as String: i.value as String},
|
||||||
|
},
|
||||||
|
activeLocation: json['activeLocation'] as String?,
|
||||||
|
clubLocation: json['clubLocation'] as String?,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
class Contact {
|
||||||
|
final String firstName;
|
||||||
|
final String lastName;
|
||||||
|
final String phone;
|
||||||
|
final String email;
|
||||||
|
|
||||||
|
const Contact({
|
||||||
|
required this.firstName,
|
||||||
|
required this.lastName,
|
||||||
|
required this.phone,
|
||||||
|
required this.email,
|
||||||
|
});
|
||||||
|
|
||||||
|
String get fullName => '$firstName $lastName';
|
||||||
|
|
||||||
|
factory Contact.fromJson(Map<String, dynamic> json) => Contact(
|
||||||
|
firstName: json['firstName'] ?? '',
|
||||||
|
lastName: json['lastName'] ?? '',
|
||||||
|
phone: json['phone'] ?? '',
|
||||||
|
email: json['email'] ?? '',
|
||||||
|
);
|
||||||
|
}
|
||||||
+627
-1035
File diff suppressed because it is too large
Load Diff
+252
-177
@@ -4,27 +4,15 @@ import 'package:intl/intl.dart';
|
|||||||
import 'package:intl/date_symbol_data_local.dart';
|
import 'package:intl/date_symbol_data_local.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
import '../models/contact.dart';
|
||||||
|
import '../services/app_settings.dart';
|
||||||
|
import '../theme/app_theme.dart';
|
||||||
|
import '../widgets/bar_tabs.dart';
|
||||||
import '../services/google_calendar_service.dart';
|
import '../services/google_calendar_service.dart';
|
||||||
import '../services/notification_service.dart';
|
import '../services/notification_service.dart';
|
||||||
import '../utils/translations.dart';
|
import '../utils/translations.dart';
|
||||||
import '../utils/target_colors.dart';
|
import '../utils/target_colors.dart';
|
||||||
|
|
||||||
class Contact {
|
|
||||||
final String firstName;
|
|
||||||
final String lastName;
|
|
||||||
final String phone;
|
|
||||||
final String email;
|
|
||||||
|
|
||||||
Contact({
|
|
||||||
required this.firstName,
|
|
||||||
required this.lastName,
|
|
||||||
required this.phone,
|
|
||||||
required this.email,
|
|
||||||
});
|
|
||||||
|
|
||||||
String get fullName => '$firstName $lastName';
|
|
||||||
}
|
|
||||||
|
|
||||||
enum EventType {
|
enum EventType {
|
||||||
regular,
|
regular,
|
||||||
competition,
|
competition,
|
||||||
@@ -48,29 +36,13 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
bool _showContacts = false;
|
bool _showContacts = false;
|
||||||
late Color _backgroundColor;
|
late Color _backgroundColor;
|
||||||
|
|
||||||
final List<Contact> _contacts = [
|
List<Contact> get _contacts => AppSettings.instance.clubContacts;
|
||||||
Contact(firstName: 'Domen', lastName: 'Pleterski', phone: '051227764', email: 'info@bl3k.com'),
|
|
||||||
Contact(firstName: 'Ivan', lastName: 'Tandler', phone: '040471258', email: 'ivan.tandler@gmail.com'),
|
|
||||||
Contact(firstName: 'Jože', lastName: 'Verhnjak', phone: '041443463', email: 'joze.verhnjak@gmail.com'),
|
|
||||||
Contact(firstName: 'Branko', lastName: 'Pokeržnik', phone: '041291001', email: 'pokerznik.helena@gmail.com'),
|
|
||||||
Contact(firstName: 'Franc', lastName: 'Žigart', phone: '041439597', email: 'franc.zigart@gmail.com'),
|
|
||||||
Contact(firstName: 'Janez', lastName: 'Božič', phone: '041551704', email: 'janbozic@gmail.com'),
|
|
||||||
Contact(firstName: 'Mitja', lastName: 'Čeh', phone: '070550383', email: 'mekabara@gmail.com'),
|
|
||||||
Contact(firstName: 'Rado', lastName: 'Keter', phone: '041324529', email: 'rado.keter@gmail.com'),
|
|
||||||
Contact(firstName: 'Karli', lastName: 'Proje', phone: '040424951', email: 'karl.project@gmail.com'),
|
|
||||||
Contact(firstName: 'Jan', lastName: 'Pleterski', phone: '041842063', email: 'jan.pleterski1997@gmail.com'),
|
|
||||||
Contact(firstName: 'Silvo', lastName: 'Poročnik', phone: '040860618', email: 'skobar.silvo@gmail.com'),
|
|
||||||
Contact(firstName: 'Dušan', lastName: 'Onuk', phone: '070448303', email: 'dusan.onuk@gmail.com'),
|
|
||||||
Contact(firstName: 'Matjaž', lastName: 'Pleterski', phone: '041603859', email: 'matjaz.pleterski@gmail.com'),
|
|
||||||
Contact(firstName: 'Marko', lastName: 'Blimen', phone: '031610857', email: 'blimenmarko@gmail.com'),
|
|
||||||
Contact(firstName: 'Doris', lastName: 'Fesel', phone: '070373987', email: 'doris.fesel@gmail.com'),
|
|
||||||
];
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
initializeDateFormatting('sl_SI', null);
|
initializeDateFormatting('sl_SI', null);
|
||||||
_backgroundColor = TargetColors.getBackgroundColor('assets/target.png');
|
_backgroundColor = AppSettings.instance.backgroundColor;
|
||||||
_loadBulletColor();
|
_loadBulletColor();
|
||||||
_loadLanguage();
|
_loadLanguage();
|
||||||
_loadSelectedTargetColor();
|
_loadSelectedTargetColor();
|
||||||
@@ -81,13 +53,16 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
|
|
||||||
Future<void> _loadLanguage() async {
|
Future<void> _loadLanguage() async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
setState(() => _selectedLanguage = prefs.getString('language') ?? 'English');
|
setState(
|
||||||
|
() => _selectedLanguage = prefs.getString('language') ?? 'English');
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadSelectedTargetColor() async {
|
Future<void> _loadSelectedTargetColor() async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
final selectedTarget = prefs.getString('selectedTarget') ?? 'assets/target.png';
|
final selectedTarget =
|
||||||
setState(() => _backgroundColor = TargetColors.getBackgroundColor(selectedTarget));
|
prefs.getString('selectedTarget') ?? 'assets/target.png';
|
||||||
|
setState(() =>
|
||||||
|
_backgroundColor = TargetColors.getBackgroundColor(selectedTarget));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -103,22 +78,38 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
|
|
||||||
Color _getAccentColor() {
|
Color _getAccentColor() {
|
||||||
switch (_bulletColor.toLowerCase()) {
|
switch (_bulletColor.toLowerCase()) {
|
||||||
case 'blue': return Colors.blue;
|
case 'blue':
|
||||||
case 'green': return Colors.green;
|
return Colors.blue;
|
||||||
case 'yellow': return Colors.yellow;
|
case 'green':
|
||||||
case 'purple': return Colors.purple;
|
return Colors.green;
|
||||||
case 'cyan': return Colors.cyan;
|
case 'yellow':
|
||||||
case 'teal': return Colors.teal;
|
return Colors.yellow;
|
||||||
case 'indigo': return Colors.indigo;
|
case 'purple':
|
||||||
case 'pink': return Colors.pink;
|
return Colors.purple;
|
||||||
case 'lime': return Colors.lime;
|
case 'cyan':
|
||||||
case 'mint': return Colors.greenAccent;
|
return Colors.cyan;
|
||||||
case 'orange': return Colors.orange;
|
case 'teal':
|
||||||
case 'violet': return Colors.deepPurpleAccent;
|
return Colors.teal;
|
||||||
case 'amber': return Colors.amber;
|
case 'indigo':
|
||||||
case 'brown': return Colors.brown;
|
return Colors.indigo;
|
||||||
case 'grey': return Colors.grey;
|
case 'pink':
|
||||||
default: return Colors.blue;
|
return Colors.pink;
|
||||||
|
case 'lime':
|
||||||
|
return Colors.lime;
|
||||||
|
case 'mint':
|
||||||
|
return Colors.greenAccent;
|
||||||
|
case 'orange':
|
||||||
|
return Colors.orange;
|
||||||
|
case 'violet':
|
||||||
|
return Colors.deepPurpleAccent;
|
||||||
|
case 'amber':
|
||||||
|
return Colors.amber;
|
||||||
|
case 'brown':
|
||||||
|
return Colors.brown;
|
||||||
|
case 'grey':
|
||||||
|
return Colors.grey;
|
||||||
|
default:
|
||||||
|
return Colors.blue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +121,9 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
EventType? _getEventType(CalendarEvent event) {
|
EventType? _getEventType(CalendarEvent event) {
|
||||||
if (event.summary == null) return null;
|
if (event.summary == null) return null;
|
||||||
final summary = event.summary!.toLowerCase();
|
final summary = event.summary!.toLowerCase();
|
||||||
if (summary.contains('liga') || summary.contains('tekmovanje') || summary.contains('tekma')) {
|
if (summary.contains('liga') ||
|
||||||
|
summary.contains('tekmovanje') ||
|
||||||
|
summary.contains('tekma')) {
|
||||||
return EventType.competition;
|
return EventType.competition;
|
||||||
} else if (summary.contains('sestanek')) {
|
} else if (summary.contains('sestanek')) {
|
||||||
return EventType.sestanek;
|
return EventType.sestanek;
|
||||||
@@ -159,7 +152,8 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
if (!_isValidEvent(event)) return false;
|
if (!_isValidEvent(event)) return false;
|
||||||
if (_getEventType(event) == null) return false;
|
if (_getEventType(event) == null) return false;
|
||||||
if (event.startTime != null) {
|
if (event.startTime != null) {
|
||||||
final eventDate = DateTime(event.startTime!.year, event.startTime!.month, event.startTime!.day);
|
final eventDate = DateTime(event.startTime!.year,
|
||||||
|
event.startTime!.month, event.startTime!.day);
|
||||||
return eventDate.isAtSameMomentAs(today) || eventDate.isAfter(today);
|
return eventDate.isAtSameMomentAs(today) || eventDate.isAfter(today);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -225,7 +219,9 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||||
),
|
),
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return RepaintBoundary(
|
// SafeArea keeps the buttons above Android's gesture bar (edge-to-edge)
|
||||||
|
return SafeArea(
|
||||||
|
child: RepaintBoundary(
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.all(20),
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -246,7 +242,10 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
contact.firstName[0].toUpperCase(),
|
contact.firstName[0].toUpperCase(),
|
||||||
style: const TextStyle(color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold),
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 24,
|
||||||
|
fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -254,33 +253,41 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
_capitalize(contact.fullName),
|
_capitalize(contact.fullName),
|
||||||
style: const TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
_buildContactDetailRow(accentColor, Icons.phone, _t('Phone'), contact.phone, () {
|
_buildContactDetailRow(
|
||||||
|
accentColor, Icons.phone, _t('Phone'), contact.phone, () {
|
||||||
_copyToClipboard(contact.phone, 'Phone number');
|
_copyToClipboard(contact.phone, 'Phone number');
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
}),
|
}),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
_buildContactDetailRow(accentColor, Icons.email, _t('Email'), contact.email.toLowerCase(), () {
|
_buildContactDetailRow(accentColor, Icons.email, _t('Email'),
|
||||||
|
contact.email.toLowerCase(), () {
|
||||||
_copyToClipboard(contact.email, 'Email address');
|
_copyToClipboard(contact.email, 'Email address');
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildContactDetailRow(Color accentColor, IconData icon, String label, String value, VoidCallback onCopy) {
|
Widget _buildContactDetailRow(Color accentColor, IconData icon, String label,
|
||||||
|
String value, VoidCallback onCopy) {
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 12),
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 12),
|
||||||
decoration: BoxDecoration(color: Colors.grey[850], borderRadius: BorderRadius.circular(10)),
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey[850], borderRadius: BorderRadius.circular(10)),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(icon, color: accentColor, size: 20),
|
Icon(icon, color: accentColor, size: 20),
|
||||||
@@ -289,13 +296,21 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(label, style: const TextStyle(color: Colors.grey, fontSize: 11)),
|
Text(label,
|
||||||
Text(value, style: const TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w600), maxLines: 1, overflow: TextOverflow.ellipsis),
|
style: const TextStyle(color: Colors.grey, fontSize: 11)),
|
||||||
|
Text(value,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w600),
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
decoration: BoxDecoration(color: accentColor, borderRadius: BorderRadius.circular(8)),
|
decoration: BoxDecoration(
|
||||||
|
color: accentColor, borderRadius: BorderRadius.circular(8)),
|
||||||
child: Material(
|
child: Material(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
@@ -303,7 +318,8 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
child: const Padding(
|
child: const Padding(
|
||||||
padding: EdgeInsets.all(8),
|
padding: EdgeInsets.all(8),
|
||||||
child: Icon(Icons.content_copy, color: Colors.white, size: 18),
|
child:
|
||||||
|
Icon(Icons.content_copy, color: Colors.white, size: 18),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -321,15 +337,18 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final contact = _contacts[index];
|
final contact = _contacts[index];
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () => _makePhoneCall(contact.phone),
|
// Card opens the info sheet (copy number/e-mail); the call strip on the right calls
|
||||||
onLongPress: () => _showContactPopup(context, contact),
|
onTap: () => _showContactPopup(context, contact),
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.grey[300],
|
color: Surfaces.current.card,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(color: Colors.grey.withValues(alpha: 0.3), blurRadius: 8, offset: const Offset(0, 2)),
|
BoxShadow(
|
||||||
|
color: Colors.black.withValues(alpha: 0.15),
|
||||||
|
blurRadius: 6,
|
||||||
|
offset: const Offset(0, 2)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: Stack(
|
child: Stack(
|
||||||
@@ -339,44 +358,62 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 16, vertical: 12),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: accentColor.withValues(alpha: 0.6),
|
color: accentColor.withValues(alpha: 0.6),
|
||||||
borderRadius: const BorderRadius.only(topLeft: Radius.circular(12), topRight: Radius.circular(12)),
|
borderRadius: const BorderRadius.only(
|
||||||
|
topLeft: Radius.circular(12),
|
||||||
|
topRight: Radius.circular(12)),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
width: 4,
|
width: 4,
|
||||||
height: 20,
|
height: 20,
|
||||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(2)),
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(2)),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
_capitalize(contact.fullName),
|
_capitalize(contact.fullName),
|
||||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.white),
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.white),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6),
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 14, vertical: 6),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Row(children: [
|
Row(children: [
|
||||||
Icon(Icons.phone, size: 14, color: accentColor),
|
Icon(Icons.phone, size: 14, color: accentColor),
|
||||||
const SizedBox(width: 6),
|
const SizedBox(width: 6),
|
||||||
Text(contact.phone, style: const TextStyle(fontSize: 12, color: Colors.black87, fontWeight: FontWeight.w500)),
|
Text(contact.phone,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: Surfaces.current.textPrimary,
|
||||||
|
fontWeight: FontWeight.w500)),
|
||||||
]),
|
]),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
Row(children: [
|
Row(children: [
|
||||||
Icon(Icons.email, size: 14, color: accentColor),
|
Icon(Icons.email, size: 14, color: accentColor),
|
||||||
const SizedBox(width: 6),
|
const SizedBox(width: 6),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(contact.email.toLowerCase(), style: const TextStyle(fontSize: 12, color: Colors.black87, fontWeight: FontWeight.w500), overflow: TextOverflow.ellipsis),
|
child: Text(contact.email.toLowerCase(),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: Surfaces.current.textPrimary,
|
||||||
|
fontWeight: FontWeight.w500),
|
||||||
|
overflow: TextOverflow.ellipsis),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
@@ -385,19 +422,27 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
Positioned(
|
Positioned(
|
||||||
right: 0, top: 0, bottom: 0,
|
right: 0,
|
||||||
|
top: 0,
|
||||||
|
bottom: 0,
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 80,
|
width: 80,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: accentColor,
|
color: accentColor,
|
||||||
borderRadius: const BorderRadius.only(topRight: Radius.circular(10), bottomRight: Radius.circular(10)),
|
borderRadius: const BorderRadius.only(
|
||||||
|
topRight: Radius.circular(10),
|
||||||
|
bottomRight: Radius.circular(10)),
|
||||||
),
|
),
|
||||||
child: Material(
|
child: Material(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () => _makePhoneCall(contact.phone),
|
onTap: () => _makePhoneCall(contact.phone),
|
||||||
borderRadius: const BorderRadius.only(topRight: Radius.circular(10), bottomRight: Radius.circular(10)),
|
borderRadius: const BorderRadius.only(
|
||||||
child: const Center(child: Icon(Icons.call, color: Colors.white, size: 22)),
|
topRight: Radius.circular(10),
|
||||||
|
bottomRight: Radius.circular(10)),
|
||||||
|
child: const Center(
|
||||||
|
child: Icon(Icons.call,
|
||||||
|
color: Colors.white, size: 22)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -412,48 +457,64 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
|
|
||||||
Color _eventColor(EventType type, Color accentColor) {
|
Color _eventColor(EventType type, Color accentColor) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case EventType.competition: return Colors.orange;
|
case EventType.competition:
|
||||||
case EventType.sestanek: return const Color(0xFFE53935);
|
return Colors.orange;
|
||||||
case EventType.regular: return accentColor;
|
case EventType.sestanek:
|
||||||
|
return const Color(0xFFE53935);
|
||||||
|
case EventType.regular:
|
||||||
|
return accentColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IconData _eventIcon(EventType type) {
|
IconData _eventIcon(EventType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case EventType.competition: return Icons.emoji_events;
|
case EventType.competition:
|
||||||
case EventType.sestanek: return Icons.people;
|
return Icons.emoji_events;
|
||||||
case EventType.regular: return Icons.calendar_today;
|
case EventType.sestanek:
|
||||||
|
return Icons.people;
|
||||||
|
case EventType.regular:
|
||||||
|
return Icons.calendar_today;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String _eventBadgeLabel(EventType type) {
|
String _eventBadgeLabel(EventType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case EventType.competition: return _t('COMPETITION');
|
case EventType.competition:
|
||||||
case EventType.sestanek: return _t('MEETING');
|
return _t('COMPETITION');
|
||||||
case EventType.regular: return _t('DUTY');
|
case EventType.sestanek:
|
||||||
|
return _t('MEETING');
|
||||||
|
case EventType.regular:
|
||||||
|
return _t('DUTY');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String _timeText(CalendarEvent event) {
|
String _timeText(CalendarEvent event) {
|
||||||
final startTime = event.startTime;
|
final startTime = event.startTime;
|
||||||
if (event.isAllDay || startTime == null || event.endTime == null) return _t('All day');
|
if (event.isAllDay || startTime == null || event.endTime == null)
|
||||||
|
return _t('All day');
|
||||||
return '${DateFormat('HH:mm').format(startTime.toLocal())} – ${DateFormat('HH:mm').format(event.endTime!.toLocal())}';
|
return '${DateFormat('HH:mm').format(startTime.toLocal())} – ${DateFormat('HH:mm').format(event.endTime!.toLocal())}';
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildEventCard(CalendarEvent event, Color accentColor, {bool highlight = false}) {
|
// When [date] is given, the type stripe widens into a date block (upcoming list).
|
||||||
|
Widget _buildEventCard(CalendarEvent event, Color accentColor,
|
||||||
|
{bool highlight = false, DateTime? date, int daysFromToday = 0}) {
|
||||||
final eventType = _getEventType(event);
|
final eventType = _getEventType(event);
|
||||||
if (eventType == null) return const SizedBox();
|
if (eventType == null) return const SizedBox();
|
||||||
|
|
||||||
final color = _eventColor(eventType, accentColor);
|
final color = _eventColor(eventType, accentColor);
|
||||||
final hasLocation = event.location != null && event.location!.isNotEmpty;
|
final hasLocation = event.location != null && event.location!.isNotEmpty;
|
||||||
|
|
||||||
|
final surf = Surfaces.current;
|
||||||
return RepaintBoundary(
|
return RepaintBoundary(
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.grey[300],
|
color: surf.card,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(color: Colors.black.withValues(alpha: 0.15), blurRadius: 6, offset: const Offset(0, 2)),
|
BoxShadow(
|
||||||
|
color: Colors.black.withValues(alpha: 0.15),
|
||||||
|
blurRadius: 6,
|
||||||
|
offset: const Offset(0, 2)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
clipBehavior: Clip.antiAlias,
|
clipBehavior: Clip.antiAlias,
|
||||||
@@ -461,23 +522,31 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
child: Row(
|
child: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
// Type color stripe
|
// Type color stripe, or date block for upcoming events
|
||||||
Container(width: 5, color: color),
|
date != null
|
||||||
|
? _buildDateBlock(date, daysFromToday, color)
|
||||||
|
: Container(width: 5, color: color),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.fromLTRB(12, highlight ? 12 : 10, 12, highlight ? 12 : 10),
|
padding: EdgeInsets.fromLTRB(
|
||||||
|
12, highlight ? 12 : 10, 12, highlight ? 12 : 10),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
_buildTypeChip(_eventIcon(eventType), _eventBadgeLabel(eventType), color),
|
_buildTypeChip(_eventIcon(eventType),
|
||||||
|
_eventBadgeLabel(eventType), color),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
Icon(Icons.access_time, size: 13, color: Colors.grey[700]),
|
Icon(Icons.access_time,
|
||||||
|
size: 13, color: surf.textSecondary),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
Text(
|
Text(
|
||||||
_timeText(event),
|
_timeText(event),
|
||||||
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Colors.grey[800]),
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: surf.textSecondary),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -487,19 +556,21 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: highlight ? 16 : 14,
|
fontSize: highlight ? 16 : 14,
|
||||||
fontWeight: FontWeight.w700,
|
fontWeight: FontWeight.w700,
|
||||||
color: Colors.grey[900],
|
color: surf.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (hasLocation) ...[
|
if (hasLocation) ...[
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.location_on, size: 13, color: Colors.grey[600]),
|
Icon(Icons.location_on,
|
||||||
|
size: 13, color: surf.textSecondary),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
event.location!,
|
event.location!,
|
||||||
style: TextStyle(fontSize: 12, color: Colors.grey[700]),
|
style: TextStyle(
|
||||||
|
fontSize: 12, color: surf.textSecondary),
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
@@ -530,13 +601,19 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
children: [
|
children: [
|
||||||
Icon(icon, size: 11, color: color),
|
Icon(icon, size: 11, color: color),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
Text(label, style: TextStyle(fontSize: 10, fontWeight: FontWeight.bold, color: color, letterSpacing: 0.6)),
|
Text(label,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 10,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: color,
|
||||||
|
letterSpacing: 0.6)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildSectionHeader(String label, Color dotColor, Color textColor, {String? trailing, Color? trailingColor}) {
|
Widget _buildSectionHeader(String label, Color dotColor, Color textColor,
|
||||||
|
{String? trailing, Color? trailingColor}) {
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
@@ -545,7 +622,12 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
decoration: BoxDecoration(color: dotColor, shape: BoxShape.circle),
|
decoration: BoxDecoration(color: dotColor, shape: BoxShape.circle),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Text(label, style: TextStyle(fontSize: 12, fontWeight: FontWeight.bold, color: textColor, letterSpacing: 1.4)),
|
Text(label,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: textColor,
|
||||||
|
letterSpacing: 1.4)),
|
||||||
if (trailing != null) ...[
|
if (trailing != null) ...[
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Expanded(
|
Expanded(
|
||||||
@@ -560,32 +642,43 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildDateColumn(DateTime date, int daysFromToday, Color accentColor, bool isLight) {
|
Widget _buildDateBlock(DateTime date, int daysFromToday, Color color) {
|
||||||
final locale = _selectedLanguage == 'Slovenian' ? 'sl_SI' : 'en_US';
|
final locale = _selectedLanguage == 'Slovenian' ? 'sl_SI' : 'en_US';
|
||||||
final relative = daysFromToday == 1
|
final relative = daysFromToday == 1
|
||||||
? _t('Tomorrow')
|
? _t('Tomorrow')
|
||||||
: _t('in {n} days').replaceAll('{n}', '$daysFromToday');
|
: _t('in {n} days').replaceAll('{n}', '$daysFromToday');
|
||||||
|
|
||||||
return SizedBox(
|
return Container(
|
||||||
width: 48,
|
width: 56,
|
||||||
|
color: color,
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 2),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
DateFormat('EEE', locale).format(date).toUpperCase(),
|
DateFormat('EEE', locale).format(date).toUpperCase(),
|
||||||
style: TextStyle(fontSize: 10, fontWeight: FontWeight.w700, color: isLight ? Colors.grey[700] : Colors.grey[400], letterSpacing: 0.8),
|
style: TextStyle(
|
||||||
|
fontSize: 10,
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
color: Colors.white.withValues(alpha: 0.9),
|
||||||
|
letterSpacing: 0.8),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
DateFormat('d').format(date),
|
DateFormat('d').format(date),
|
||||||
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold, color: isLight ? Colors.black87 : Colors.white, height: 1.15),
|
style: const TextStyle(
|
||||||
|
fontSize: 22,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.white,
|
||||||
|
height: 1.15),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
relative,
|
relative,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 9,
|
fontSize: 9,
|
||||||
fontWeight: daysFromToday == 1 ? FontWeight.bold : FontWeight.w500,
|
fontWeight:
|
||||||
color: daysFromToday == 1 ? accentColor : (isLight ? Colors.grey[600] : Colors.grey[500]),
|
daysFromToday == 1 ? FontWeight.bold : FontWeight.w500,
|
||||||
|
color: Colors.white.withValues(alpha: 0.9),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -606,17 +699,24 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
final textSecondary = isLight ? Colors.grey[700]! : Colors.grey[400]!;
|
final textSecondary = isLight ? Colors.grey[700]! : Colors.grey[400]!;
|
||||||
final textMuted = isLight ? Colors.grey[600]! : Colors.grey[500]!;
|
final textMuted = isLight ? Colors.grey[600]! : Colors.grey[500]!;
|
||||||
|
|
||||||
DateTime dayOf(CalendarEvent e) => DateTime(e.startTime!.year, e.startTime!.month, e.startTime!.day);
|
DateTime dayOf(CalendarEvent e) =>
|
||||||
|
DateTime(e.startTime!.year, e.startTime!.month, e.startTime!.day);
|
||||||
|
|
||||||
final todayEvents = _events.where((e) => e.startTime != null && dayOf(e).isAtSameMomentAs(today)).toList();
|
final todayEvents = _events
|
||||||
final upcomingEvents = _events.where((e) => e.startTime != null && dayOf(e).isAfter(today)).toList();
|
.where((e) => e.startTime != null && dayOf(e).isAtSameMomentAs(today))
|
||||||
|
.toList();
|
||||||
|
final upcomingEvents = _events
|
||||||
|
.where((e) => e.startTime != null && dayOf(e).isAfter(today))
|
||||||
|
.toList();
|
||||||
|
|
||||||
// Build upcoming list grouped by month, date column shown once per day
|
// Build upcoming list grouped by month, each card carries its own date block
|
||||||
final upcomingWidgets = <Widget>[];
|
final upcomingWidgets = <Widget>[];
|
||||||
DateTime? lastDay;
|
DateTime? lastDay;
|
||||||
for (final e in upcomingEvents) {
|
for (final e in upcomingEvents) {
|
||||||
final day = dayOf(e);
|
final day = dayOf(e);
|
||||||
final isNewMonth = lastDay == null || lastDay.month != day.month || lastDay.year != day.year;
|
final isNewMonth = lastDay == null ||
|
||||||
|
lastDay.month != day.month ||
|
||||||
|
lastDay.year != day.year;
|
||||||
final isNewDay = lastDay == null || !lastDay.isAtSameMomentAs(day);
|
final isNewDay = lastDay == null || !lastDay.isAtSameMomentAs(day);
|
||||||
|
|
||||||
if (isNewMonth) {
|
if (isNewMonth) {
|
||||||
@@ -624,23 +724,20 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
padding: EdgeInsets.fromLTRB(16, lastDay == null ? 4 : 18, 16, 8),
|
padding: EdgeInsets.fromLTRB(16, lastDay == null ? 4 : 18, 16, 8),
|
||||||
child: Text(
|
child: Text(
|
||||||
DateFormat('LLLL yyyy', locale).format(day).toUpperCase(),
|
DateFormat('LLLL yyyy', locale).format(day).toUpperCase(),
|
||||||
style: TextStyle(fontSize: 11, fontWeight: FontWeight.bold, color: textMuted, letterSpacing: 1.5),
|
style: TextStyle(
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: textMuted,
|
||||||
|
letterSpacing: 1.5),
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
upcomingWidgets.add(Padding(
|
upcomingWidgets.add(Padding(
|
||||||
padding: EdgeInsets.fromLTRB(12, isNewDay && !isNewMonth ? 10 : 0, 16, 8),
|
padding:
|
||||||
child: Row(
|
EdgeInsets.fromLTRB(16, isNewDay && !isNewMonth ? 10 : 0, 16, 8),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
child: _buildEventCard(e, accentColor,
|
||||||
children: [
|
date: day, daysFromToday: day.difference(today).inDays),
|
||||||
isNewDay
|
|
||||||
? _buildDateColumn(day, day.difference(today).inDays, accentColor, isLight)
|
|
||||||
: const SizedBox(width: 48),
|
|
||||||
const SizedBox(width: 10),
|
|
||||||
Expanded(child: _buildEventCard(e, accentColor)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
));
|
));
|
||||||
lastDay = day;
|
lastDay = day;
|
||||||
}
|
}
|
||||||
@@ -668,7 +765,8 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
if (todayEvents.isEmpty)
|
if (todayEvents.isEmpty)
|
||||||
Container(
|
Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 14, horizontal: 14),
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 14, horizontal: 14),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: textMuted.withValues(alpha: 0.12),
|
color: textMuted.withValues(alpha: 0.12),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
@@ -677,7 +775,9 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
children: [
|
children: [
|
||||||
Icon(Icons.event_busy, size: 18, color: textMuted),
|
Icon(Icons.event_busy, size: 18, color: textMuted),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
Text(_t('No events today'), style: TextStyle(fontSize: 13, color: textSecondary)),
|
Text(_t('No events today'),
|
||||||
|
style:
|
||||||
|
TextStyle(fontSize: 13, color: textSecondary)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -693,7 +793,8 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
if (upcomingEvents.isNotEmpty) ...[
|
if (upcomingEvents.isNotEmpty) ...[
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(16, 24, 16, 10),
|
padding: const EdgeInsets.fromLTRB(16, 24, 16, 10),
|
||||||
child: _buildSectionHeader(_t('UPCOMING'), textMuted, textPrimary),
|
child:
|
||||||
|
_buildSectionHeader(_t('UPCOMING'), textMuted, textPrimary),
|
||||||
),
|
),
|
||||||
...upcomingWidgets,
|
...upcomingWidgets,
|
||||||
],
|
],
|
||||||
@@ -705,9 +806,11 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
children: [
|
children: [
|
||||||
Icon(Icons.event_available, size: 56, color: textMuted),
|
Icon(Icons.event_available, size: 56, color: textMuted),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Text(_t('No upcoming events'), style: TextStyle(fontSize: 15, color: textMuted)),
|
Text(_t('No upcoming events'),
|
||||||
|
style: TextStyle(fontSize: 15, color: textMuted)),
|
||||||
const SizedBox(height: 6),
|
const SizedBox(height: 6),
|
||||||
Text(_t('Pull down to refresh'), style: TextStyle(fontSize: 13, color: textSecondary)),
|
Text(_t('Pull down to refresh'),
|
||||||
|
style: TextStyle(fontSize: 13, color: textSecondary)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -741,14 +844,19 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 32),
|
padding: const EdgeInsets.symmetric(horizontal: 32),
|
||||||
child: Text(_errorMessage!, textAlign: TextAlign.center, style: const TextStyle(fontSize: 16, color: Colors.white70)),
|
child: Text(_errorMessage!,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16, color: Surfaces.current.textSecondary)),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
ElevatedButton.icon(
|
ElevatedButton.icon(
|
||||||
onPressed: _loadEvents,
|
onPressed: _loadEvents,
|
||||||
icon: const Icon(Icons.refresh),
|
icon: const Icon(Icons.refresh),
|
||||||
label: Text(_t('Retry')),
|
label: Text(_t('Retry')),
|
||||||
style: ElevatedButton.styleFrom(backgroundColor: accentColor, foregroundColor: Colors.white),
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: accentColor,
|
||||||
|
foregroundColor: Colors.white),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -760,19 +868,13 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
backgroundColor: _backgroundColor,
|
backgroundColor: _backgroundColor,
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
// Tab bar
|
BarTabs(
|
||||||
Container(
|
tabs: [
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
BarTab(_t('Calendar'), Icons.calendar_month),
|
||||||
decoration: BoxDecoration(
|
BarTab(_t('Contacts'), Icons.people),
|
||||||
color: Colors.grey[900],
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
_buildTab(_t('Calendar'), Icons.calendar_month, !_showContacts, () => setState(() => _showContacts = false)),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
_buildTab(_t('Contacts'), Icons.people, _showContacts, () => setState(() => _showContacts = true)),
|
|
||||||
],
|
],
|
||||||
),
|
selected: _showContacts ? 1 : 0,
|
||||||
|
onSelect: (i) => setState(() => _showContacts = i == 1),
|
||||||
),
|
),
|
||||||
// Body
|
// Body
|
||||||
Expanded(
|
Expanded(
|
||||||
@@ -784,31 +886,4 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildTab(String label, IconData icon, bool active, VoidCallback onTap) {
|
|
||||||
return Expanded(
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: onTap,
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: active ? Colors.white : Colors.transparent,
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Icon(icon, color: active ? Colors.black : Colors.grey[400], size: 18),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Text(
|
|
||||||
label,
|
|
||||||
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: active ? Colors.black : Colors.grey[400]),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+122
-192
@@ -7,6 +7,7 @@ import 'yolo_detector.dart';
|
|||||||
import 'preview_screen.dart';
|
import 'preview_screen.dart';
|
||||||
import '../utils/translations.dart';
|
import '../utils/translations.dart';
|
||||||
import '../utils/target_colors.dart';
|
import '../utils/target_colors.dart';
|
||||||
|
import '../widgets/camera_sheet.dart';
|
||||||
|
|
||||||
class CameraScreen extends StatefulWidget {
|
class CameraScreen extends StatefulWidget {
|
||||||
const CameraScreen({super.key});
|
const CameraScreen({super.key});
|
||||||
@@ -26,9 +27,10 @@ class _CameraScreenState extends State<CameraScreen> {
|
|||||||
String _selectedLanguage = 'English';
|
String _selectedLanguage = 'English';
|
||||||
late Color _backgroundColor;
|
late Color _backgroundColor;
|
||||||
|
|
||||||
// Brightness and contrast controls
|
// Real camera controls (they change the photo itself)
|
||||||
double _brightness = 0.0; // -1.0 to 1.0
|
double _exposure = 0, _minExposure = 0, _maxExposure = 0;
|
||||||
double _contrast = 1.0; // 0.0 to 2.0
|
double _zoom = 1, _minZoom = 1, _maxZoom = 1;
|
||||||
|
bool _torch = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -40,24 +42,9 @@ class _CameraScreenState extends State<CameraScreen> {
|
|||||||
_loadBulletColor(); // 👈
|
_loadBulletColor(); // 👈
|
||||||
_loadLanguage();
|
_loadLanguage();
|
||||||
_loadSelectedTargetColor();
|
_loadSelectedTargetColor();
|
||||||
_loadBrightnessContrast();
|
|
||||||
YOLODetector.create().then((detector) => _yoloDetector = detector);
|
YOLODetector.create().then((detector) => _yoloDetector = detector);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadBrightnessContrast() async {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
setState(() {
|
|
||||||
_brightness = prefs.getDouble('brightness') ?? 0.0;
|
|
||||||
_contrast = prefs.getDouble('contrast') ?? 1.0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _saveBrightnessContrast() async {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
await prefs.setDouble('brightness', _brightness);
|
|
||||||
await prefs.setDouble('contrast', _contrast);
|
|
||||||
}
|
|
||||||
|
|
||||||
String _t(String key) {
|
String _t(String key) {
|
||||||
return AppTranslations.translate(key, _selectedLanguage);
|
return AppTranslations.translate(key, _selectedLanguage);
|
||||||
}
|
}
|
||||||
@@ -71,7 +58,8 @@ class _CameraScreenState extends State<CameraScreen> {
|
|||||||
|
|
||||||
Future<void> _loadSelectedTargetColor() async {
|
Future<void> _loadSelectedTargetColor() async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
final selectedTarget = prefs.getString('selectedTarget') ?? 'assets/target.png';
|
final selectedTarget =
|
||||||
|
prefs.getString('selectedTarget') ?? 'assets/target.png';
|
||||||
setState(() {
|
setState(() {
|
||||||
_backgroundColor = TargetColors.getBackgroundColor(selectedTarget);
|
_backgroundColor = TargetColors.getBackgroundColor(selectedTarget);
|
||||||
});
|
});
|
||||||
@@ -83,9 +71,9 @@ class _CameraScreenState extends State<CameraScreen> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
_bulletColor = _getColorFromName(selected);
|
_bulletColor = _getColorFromName(selected);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Color _getColorFromName(String colorName) {
|
Color _getColorFromName(String colorName) {
|
||||||
switch (colorName.toLowerCase()) {
|
switch (colorName.toLowerCase()) {
|
||||||
case 'blue':
|
case 'blue':
|
||||||
return Colors.blue;
|
return Colors.blue;
|
||||||
@@ -120,14 +108,13 @@ Color _getColorFromName(String colorName) {
|
|||||||
default:
|
default:
|
||||||
return Colors.blue; // fallback
|
return Colors.blue; // fallback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Future<void> _loadBulletCount() async {
|
Future<void> _loadBulletCount() async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
setState(() {
|
setState(() {
|
||||||
_numberOfBullets = prefs.getInt('bulletCount') ?? 5; // Load stored bullet count, default to 5
|
_numberOfBullets = prefs.getInt('bulletCount') ??
|
||||||
|
5; // Load stored bullet count, default to 5
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +133,13 @@ Color _getColorFromName(String colorName) {
|
|||||||
enableAudio: false,
|
enableAudio: false,
|
||||||
);
|
);
|
||||||
|
|
||||||
_initializeControllerFuture = _controller!.initialize();
|
_initializeControllerFuture = _controller!.initialize().then((_) async {
|
||||||
|
// Ranges differ per phone; read them once the camera is ready
|
||||||
|
_minExposure = await _controller!.getMinExposureOffset();
|
||||||
|
_maxExposure = await _controller!.getMaxExposureOffset();
|
||||||
|
_minZoom = await _controller!.getMinZoomLevel();
|
||||||
|
_maxZoom = (await _controller!.getMaxZoomLevel()).clamp(_minZoom, 8.0);
|
||||||
|
});
|
||||||
if (mounted) setState(() {});
|
if (mounted) setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,83 +195,40 @@ Color _getColorFromName(String colorName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to show the dialog for selecting the number of bullets
|
|
||||||
void _showBulletDialog() {
|
void _showBulletDialog() {
|
||||||
showDialog(
|
showCameraSheet(
|
||||||
context: context,
|
context,
|
||||||
builder: (BuildContext context) {
|
builder: (sheet) => StatefulBuilder(
|
||||||
return Dialog(
|
builder: (context, setSheetState) => Column(
|
||||||
backgroundColor: Colors.grey[900],
|
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(24.0), // Increased padding for better spacing
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
CameraSheetHeader(
|
||||||
padding: const EdgeInsets.only(bottom: 16.0),
|
title: _t('Select the number of bullets'), subtitle: '1 – 10'),
|
||||||
child: Text(
|
SheetStepper(
|
||||||
_t('Select the number of bullets'),
|
value: _numberOfBullets,
|
||||||
textAlign: TextAlign.center,
|
min: 1,
|
||||||
style: const TextStyle(
|
max: 10,
|
||||||
color: Colors.white,
|
accent: _bulletColor,
|
||||||
fontSize: 20,
|
onChanged: (n) {
|
||||||
fontWeight: FontWeight.bold,
|
_selectBulletCount(n);
|
||||||
),
|
setSheetState(() {});
|
||||||
),
|
|
||||||
),
|
|
||||||
Center(
|
|
||||||
child: Wrap(
|
|
||||||
alignment: WrapAlignment.center,
|
|
||||||
spacing: 12,
|
|
||||||
runSpacing: 12,
|
|
||||||
children: List.generate(5, (index) {
|
|
||||||
final bulletNum = index + 1;
|
|
||||||
final isSelected = _numberOfBullets == bulletNum;
|
|
||||||
return ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
_selectBulletCount(bulletNum);
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor:
|
|
||||||
isSelected ? _bulletColor : Colors.grey[800],
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
padding:
|
|
||||||
const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
'$bulletNum',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight:
|
|
||||||
isSelected ? FontWeight.bold : FontWeight.normal,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void _showHelpDialog() {
|
void _showHelpDialog() {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return Dialog(
|
return Dialog(
|
||||||
backgroundColor: Colors.grey[900],
|
backgroundColor: Colors.grey[900],
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
shape:
|
||||||
|
RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(24.0),
|
padding: const EdgeInsets.all(24.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -287,16 +237,23 @@ Color _getColorFromName(String colorName) {
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
_t('Help'),
|
_t('Help'),
|
||||||
style: const TextStyle(color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold),
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 24,
|
||||||
|
fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
_buildHelpItem(Icons.camera_alt, _t('Tap camera button to capture and detect bullets')),
|
_buildHelpItem(Icons.camera_alt,
|
||||||
|
_t('Tap camera button to capture and detect bullets')),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
_buildHelpItem(Icons.filter_9_plus, _t('Bottom left number: Set expected bullet count (1-5)')),
|
_buildHelpItem(Icons.filter_9_plus,
|
||||||
|
_t('Bottom left number: Set expected bullet count (1-5)')),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
_buildHelpItem(Icons.brightness_6, _t('Sun icon: Adjust brightness and contrast for better visibility')),
|
_buildHelpItem(Icons.tune,
|
||||||
|
_t('Settings icon: exposure, zoom and flashlight')),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
_buildHelpItem(Icons.crop_square, _t('Align target inside the square frame')),
|
_buildHelpItem(Icons.crop_square,
|
||||||
|
_t('Align target inside the square frame')),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Center(
|
Center(
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
@@ -332,116 +289,88 @@ Color _getColorFromName(String colorName) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showBrightnessContrastDialog() {
|
void _showCameraControls() {
|
||||||
showDialog(
|
showCameraSheet(
|
||||||
context: context,
|
context,
|
||||||
builder: (BuildContext context) {
|
builder: (sheet) => StatefulBuilder(
|
||||||
return StatefulBuilder(
|
builder: (context, setSheetState) {
|
||||||
builder: (context, setDialogState) {
|
Future<void> apply(
|
||||||
return Dialog(
|
VoidCallback change, Future<void> Function() camera) async {
|
||||||
backgroundColor: Colors.grey[900],
|
setState(change);
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
setSheetState(() {});
|
||||||
child: Padding(
|
try {
|
||||||
padding: const EdgeInsets.all(24.0),
|
await camera();
|
||||||
child: Column(
|
} catch (_) {} // control not supported on this phone
|
||||||
|
}
|
||||||
|
|
||||||
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
_t('Brightness & Contrast'),
|
|
||||||
style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
// Brightness slider
|
|
||||||
Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
CameraSheetHeader(
|
||||||
'${_t('Brightness')}: ${(_brightness * 100).toInt()}',
|
title: _t('Image Settings'),
|
||||||
style: const TextStyle(color: Colors.white, fontSize: 16),
|
trailing: TextButton.icon(
|
||||||
|
style: TextButton.styleFrom(foregroundColor: Colors.white70),
|
||||||
|
icon: const Icon(Icons.restart_alt_rounded, size: 18),
|
||||||
|
label: Text(_t('Reset')),
|
||||||
|
onPressed: () => apply(() {
|
||||||
|
_exposure = 0;
|
||||||
|
_zoom = _minZoom;
|
||||||
|
}, () async {
|
||||||
|
await _controller!.setExposureOffset(0);
|
||||||
|
await _controller!.setZoomLevel(_minZoom);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (_maxExposure > _minExposure)
|
||||||
|
SheetSlider(
|
||||||
|
icon: Icons.exposure_rounded,
|
||||||
|
label: _t('Exposure'),
|
||||||
|
valueText:
|
||||||
|
'${_exposure >= 0 ? '+' : ''}${_exposure.toStringAsFixed(1)}',
|
||||||
|
value: _exposure,
|
||||||
|
min: _minExposure,
|
||||||
|
max: _maxExposure,
|
||||||
|
accent: _bulletColor,
|
||||||
|
onChanged: (v) => apply(() => _exposure = v,
|
||||||
|
() => _controller!.setExposureOffset(v)),
|
||||||
|
),
|
||||||
|
if (_maxZoom > _minZoom)
|
||||||
|
SheetSlider(
|
||||||
|
icon: Icons.zoom_in_rounded,
|
||||||
|
label: _t('Zoom'),
|
||||||
|
valueText: '${_zoom.toStringAsFixed(1)}×',
|
||||||
|
value: _zoom,
|
||||||
|
min: _minZoom,
|
||||||
|
max: _maxZoom,
|
||||||
|
accent: _bulletColor,
|
||||||
|
onChanged: (v) => apply(
|
||||||
|
() => _zoom = v, () => _controller!.setZoomLevel(v)),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: SheetToggle(
|
||||||
|
icon: _torch
|
||||||
|
? Icons.flashlight_on_rounded
|
||||||
|
: Icons.flashlight_off_rounded,
|
||||||
|
label: _t('Flashlight'),
|
||||||
|
active: _torch,
|
||||||
|
accent: _bulletColor,
|
||||||
|
onTap: () => apply(
|
||||||
|
() => _torch = !_torch,
|
||||||
|
() => _controller!
|
||||||
|
.setFlashMode(_torch ? FlashMode.torch : FlashMode.off),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
Slider(
|
|
||||||
value: _brightness,
|
|
||||||
min: -1.0,
|
|
||||||
max: 1.0,
|
|
||||||
divisions: 40,
|
|
||||||
activeColor: _bulletColor,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
_brightness = value;
|
|
||||||
});
|
|
||||||
setDialogState(() {});
|
|
||||||
_saveBrightnessContrast();
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
// Contrast slider
|
|
||||||
Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'${_t('Contrast')}: ${(_contrast * 100).toInt()}%',
|
|
||||||
style: const TextStyle(color: Colors.white, fontSize: 16),
|
|
||||||
),
|
|
||||||
Slider(
|
|
||||||
value: _contrast,
|
|
||||||
min: 0.5,
|
|
||||||
max: 2.0,
|
|
||||||
divisions: 30,
|
|
||||||
activeColor: _bulletColor,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
_contrast = value;
|
|
||||||
});
|
|
||||||
setDialogState(() {});
|
|
||||||
_saveBrightnessContrast();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
||||||
children: [
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
_brightness = 0.0;
|
|
||||||
_contrast = 1.0;
|
|
||||||
});
|
|
||||||
setDialogState(() {});
|
|
||||||
_saveBrightnessContrast();
|
|
||||||
},
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.grey[800],
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
),
|
|
||||||
child: Text(_t('Reset')),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: _bulletColor,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
),
|
|
||||||
child: Text(_t('Done')),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the bullet count and save it
|
|
||||||
void _selectBulletCount(int number) {
|
void _selectBulletCount(int number) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_numberOfBullets = number; // Update the selected number
|
_numberOfBullets = number; // Update the selected number
|
||||||
@@ -519,8 +448,9 @@ Color _getColorFromName(String colorName) {
|
|||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.brightness_6, color: Colors.white, size: 24),
|
icon:
|
||||||
onPressed: _showBrightnessContrastDialog,
|
const Icon(Icons.tune, color: Colors.white, size: 24),
|
||||||
|
onPressed: _showCameraControls,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -0,0 +1,161 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../models/camera_setup.dart';
|
||||||
|
import '../services/app_settings.dart';
|
||||||
|
import '../theme/app_theme.dart';
|
||||||
|
import '../widgets/section.dart';
|
||||||
|
import '../widgets/text_prompt.dart';
|
||||||
|
|
||||||
|
/// Locations (strelišča), number of positions, and the camera IP of every
|
||||||
|
/// position at every location.
|
||||||
|
class CameraSettingsScreen extends StatelessWidget {
|
||||||
|
const CameraSettingsScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ListenableBuilder(
|
||||||
|
listenable: AppSettings.instance,
|
||||||
|
builder: (context, _) {
|
||||||
|
final s = AppSettings.instance;
|
||||||
|
final t = s.t;
|
||||||
|
final setup = s.cameras;
|
||||||
|
final surf = Surfaces.current;
|
||||||
|
const firstPort = CameraSetup.firstPort;
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: s.backgroundColor,
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(t('Cameras'), style: const TextStyle(color: Colors.white)),
|
||||||
|
backgroundColor: AppTheme.bar,
|
||||||
|
iconTheme: const IconThemeData(color: Colors.white),
|
||||||
|
scrolledUnderElevation: 0,
|
||||||
|
),
|
||||||
|
body: ListView(
|
||||||
|
// Keep the last row clear of the system gesture bar (edge-to-edge)
|
||||||
|
padding: EdgeInsets.fromLTRB(16, 4, 16, 24 + MediaQuery.paddingOf(context).bottom),
|
||||||
|
children: [
|
||||||
|
SectionHeader(t('Locations')),
|
||||||
|
GroupCard(children: [
|
||||||
|
for (final location in setup.locations)
|
||||||
|
SettingsTile(
|
||||||
|
leading: Icon(
|
||||||
|
location == setup.clubLocation ? Icons.verified_rounded : Icons.place_rounded,
|
||||||
|
color: location == setup.clubLocation ? Colors.green : s.bulletColor,
|
||||||
|
),
|
||||||
|
title: location,
|
||||||
|
subtitle: location == setup.clubLocation ? t('Added with the club code') : null,
|
||||||
|
value: t('{n} cameras').replaceAll('{n}', '${setup.camerasIn(location)}'),
|
||||||
|
onTap: () => _editLocation(context, location),
|
||||||
|
),
|
||||||
|
SettingsTile(
|
||||||
|
leading: Icon(Icons.add_rounded, color: surf.textSecondary),
|
||||||
|
title: t('Add location'),
|
||||||
|
onTap: () => _addLocation(context),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
|
||||||
|
SectionHeader(t('Positions')),
|
||||||
|
GroupCard(children: [
|
||||||
|
SettingsTile(
|
||||||
|
title: t('Number of positions'),
|
||||||
|
trailing: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.remove_rounded),
|
||||||
|
color: surf.textPrimary,
|
||||||
|
onPressed: setup.positions > 1 ? () => s.setPositionCount(setup.positions - 1) : null,
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 28,
|
||||||
|
child: Text(
|
||||||
|
'${setup.positions}',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: surf.textPrimary),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.add_rounded),
|
||||||
|
color: surf.textPrimary,
|
||||||
|
onPressed: setup.positions < CameraSetup.maxPositions
|
||||||
|
? () => s.setPositionCount(setup.positions + 1)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
|
||||||
|
for (final location in setup.locations) ...[
|
||||||
|
SectionHeader(location),
|
||||||
|
GroupCard(children: [
|
||||||
|
SettingsTile(
|
||||||
|
leading: Icon(Icons.bolt_rounded, color: s.bulletColor),
|
||||||
|
title: t('Set all cameras from one IP'),
|
||||||
|
subtitle: t('Ports {from}–{to}')
|
||||||
|
.replaceAll('{from}', '$firstPort')
|
||||||
|
.replaceAll('{to}', '${firstPort + setup.positions - 1}'),
|
||||||
|
onTap: () => _editHost(context, location),
|
||||||
|
),
|
||||||
|
for (int p = 1; p <= setup.positions; p++)
|
||||||
|
SettingsTile(
|
||||||
|
title: '${t('Camera')} $p',
|
||||||
|
value: setup.ipFor(p, location).isEmpty ? '—' : setup.ipFor(p, location),
|
||||||
|
onTap: () => _editCamera(context, p, location),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _addLocation(BuildContext context) async {
|
||||||
|
final s = AppSettings.instance;
|
||||||
|
final name = await showTextPrompt(context, title: s.t('Add location'), hint: s.t('e.g. Home'));
|
||||||
|
if (name == null || name.isEmpty) return;
|
||||||
|
if (!await s.addLocation(name) && context.mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(s.t('This location already exists'))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _editLocation(BuildContext context, String location) async {
|
||||||
|
final s = AppSettings.instance;
|
||||||
|
final name = await showTextPrompt(
|
||||||
|
context,
|
||||||
|
title: s.t('Location'),
|
||||||
|
initial: location,
|
||||||
|
resetLabel: s.t('Delete'),
|
||||||
|
onReset: () => s.removeLocation(location),
|
||||||
|
);
|
||||||
|
if (name != null && name.isNotEmpty && name != location) await s.renameLocation(location, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _editHost(BuildContext context, String location) async {
|
||||||
|
final s = AppSettings.instance;
|
||||||
|
final first = s.cameras.ipFor(1, location);
|
||||||
|
final host = await showTextPrompt(
|
||||||
|
context,
|
||||||
|
title: '${s.t('Set all cameras from one IP')} · $location',
|
||||||
|
initial: first.split(':').first,
|
||||||
|
hint: '192.168.0.10',
|
||||||
|
keyboardType: TextInputType.url,
|
||||||
|
);
|
||||||
|
if (host != null && host.isNotEmpty) s.setLocationHost(location, host);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _editCamera(BuildContext context, int position, String location) async {
|
||||||
|
final s = AppSettings.instance;
|
||||||
|
final ip = await showTextPrompt(
|
||||||
|
context,
|
||||||
|
title: '${s.t('Camera')} $position · $location',
|
||||||
|
initial: s.cameras.ipFor(position, location),
|
||||||
|
hint: '192.168.0.10:${CameraSetup.firstPort + position - 1}',
|
||||||
|
keyboardType: TextInputType.url,
|
||||||
|
resetLabel: s.t('Remove'),
|
||||||
|
onReset: () => s.setCameraIp(position, location, ''),
|
||||||
|
);
|
||||||
|
if (ip != null && ip.isNotEmpty) s.setCameraIp(position, location, ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,118 +4,96 @@ import 'calendar_screen.dart';
|
|||||||
import 'settings_screen.dart';
|
import 'settings_screen.dart';
|
||||||
import 'target_screen.dart';
|
import 'target_screen.dart';
|
||||||
import '../widgets/bottom_nav.dart';
|
import '../widgets/bottom_nav.dart';
|
||||||
//import 'login_screen.dart';
|
|
||||||
import 'camera_screen.dart';
|
import 'camera_screen.dart';
|
||||||
import 'spectator_screen.dart';
|
import 'spectator_screen.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import '../services/app_settings.dart';
|
||||||
import '../utils/translations.dart';
|
import '../theme/app_theme.dart';
|
||||||
import '../utils/target_colors.dart';
|
|
||||||
|
enum AppTab { book, shooting, camera, calendar, settings }
|
||||||
|
|
||||||
class HomeScreen extends StatefulWidget {
|
class HomeScreen extends StatefulWidget {
|
||||||
const HomeScreen({super.key});
|
const HomeScreen({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_HomeScreenState createState() => _HomeScreenState();
|
State<HomeScreen> createState() => _HomeScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _HomeScreenState extends State<HomeScreen> {
|
class _HomeScreenState extends State<HomeScreen> {
|
||||||
int _selectedIndex = 1; // Default to Shooting Screen
|
AppTab _selected = AppTab.shooting;
|
||||||
String _selectedLanguage = 'English';
|
|
||||||
String _selectedTarget = 'assets/target.png';
|
|
||||||
late Color _backgroundColor;
|
|
||||||
|
|
||||||
static final List<Widget> _pages = <Widget>[
|
static const Map<AppTab, String> _titles = {
|
||||||
BookScreen(),
|
AppTab.book: 'Book',
|
||||||
TargetScreen(),
|
AppTab.shooting: 'Shooting',
|
||||||
Placeholder(), // Placeholder for Scan - optional
|
AppTab.camera: 'Camera',
|
||||||
CalendarScreen(),
|
AppTab.calendar: 'Calendar',
|
||||||
SettingsScreen(),
|
AppTab.settings: 'Settings',
|
||||||
|
};
|
||||||
|
|
||||||
|
static const Map<AppTab, IconData> _icons = {
|
||||||
|
AppTab.book: Icons.book,
|
||||||
|
AppTab.shooting: Icons.my_location,
|
||||||
|
AppTab.camera: Icons.camera_alt,
|
||||||
|
AppTab.calendar: Icons.calendar_today,
|
||||||
|
AppTab.settings: Icons.settings,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Calendar is only shown to club members (see Settings > Club code)
|
||||||
|
List<AppTab> get _visibleTabs => [
|
||||||
|
for (final tab in AppTab.values)
|
||||||
|
if (tab != AppTab.calendar || AppSettings.instance.clubUnlocked) tab,
|
||||||
];
|
];
|
||||||
|
|
||||||
final List<String> _pageTitles = [
|
Widget _page(AppTab tab) {
|
||||||
'Book',
|
switch (tab) {
|
||||||
'Shooting',
|
case AppTab.book:
|
||||||
'Scan',
|
return const BookScreen();
|
||||||
'Calendar',
|
case AppTab.shooting:
|
||||||
'Settings'
|
case AppTab.camera: // camera opens as its own route, never shown here
|
||||||
];
|
return const TargetScreen();
|
||||||
|
case AppTab.calendar:
|
||||||
@override
|
return const CalendarScreen();
|
||||||
void initState() {
|
case AppTab.settings:
|
||||||
super.initState();
|
return const SettingsScreen();
|
||||||
// Initialize with default target background color
|
}
|
||||||
_backgroundColor = TargetColors.getBackgroundColor('assets/target.png');
|
|
||||||
_loadLanguage();
|
|
||||||
_loadSelectedTarget();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String _t(String key) {
|
void _onTabTapped(AppTab tab) {
|
||||||
return AppTranslations.translate(key, _selectedLanguage);
|
if (tab == AppTab.camera) {
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _loadLanguage() async {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
setState(() {
|
|
||||||
_selectedLanguage = prefs.getString('language') ?? 'English';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _loadSelectedTarget() async {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
final selectedTarget =
|
|
||||||
prefs.getString('selectedTarget') ?? 'assets/target.png';
|
|
||||||
setState(() {
|
|
||||||
_selectedTarget = selectedTarget;
|
|
||||||
_backgroundColor = TargetColors.getBackgroundColor(selectedTarget);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onItemTapped(int index) {
|
|
||||||
if (index == 2) {
|
|
||||||
_openCameraScan();
|
_openCameraScan();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() => _selected = tab);
|
||||||
_selectedIndex = index;
|
|
||||||
});
|
|
||||||
// Reload language when switching screens to pick up any changes from Settings
|
|
||||||
_loadLanguage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//void _logout() {
|
// When returning from the camera screen, always land on the Shooting tab
|
||||||
// Navigator.of(context).pushAndRemoveUntil(
|
|
||||||
// MaterialPageRoute(builder: (context) => const LoginScreen()),
|
|
||||||
// (Route<dynamic> route) => false,
|
|
||||||
// );
|
|
||||||
//}
|
|
||||||
|
|
||||||
// When opening the camera screen, ensure the shooting screen is always selected after returning
|
|
||||||
void _openCameraScan() async {
|
void _openCameraScan() async {
|
||||||
// Navigate to CameraScreen
|
|
||||||
await Navigator.of(context).push(
|
await Navigator.of(context).push(
|
||||||
MaterialPageRoute(builder: (context) => const CameraScreen()),
|
MaterialPageRoute(builder: (context) => const CameraScreen()),
|
||||||
);
|
);
|
||||||
|
setState(() => _selected = AppTab.shooting);
|
||||||
// After returning, ensure that Shooting screen (index 1) is selected
|
|
||||||
setState(() {
|
|
||||||
_selectedIndex = 1;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
return ListenableBuilder(
|
||||||
|
listenable: AppSettings.instance,
|
||||||
|
builder: (context, _) {
|
||||||
|
final settings = AppSettings.instance;
|
||||||
|
final tabs = _visibleTabs;
|
||||||
|
if (!tabs.contains(_selected)) _selected = AppTab.settings; // calendar was just locked
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(
|
title: Text(
|
||||||
_t(_pageTitles[_selectedIndex]),
|
settings.t(_titles[_selected]!),
|
||||||
style: const TextStyle(color: Colors.white),
|
style: const TextStyle(color: Colors.white),
|
||||||
),
|
),
|
||||||
backgroundColor: Colors.grey[900],
|
backgroundColor: AppTheme.bar,
|
||||||
iconTheme: const IconThemeData(color: Colors.white),
|
iconTheme: const IconThemeData(color: Colors.white),
|
||||||
automaticallyImplyLeading: false,
|
automaticallyImplyLeading: false,
|
||||||
scrolledUnderElevation: 0, // For Material 3 (Flutter 3.7+)
|
scrolledUnderElevation: 0, // For Material 3 (Flutter 3.7+)
|
||||||
actions: [
|
actions: [
|
||||||
if (_selectedIndex == 1)
|
if (_selected == AppTab.shooting)
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.visibility_rounded, color: Colors.white),
|
icon: const Icon(Icons.visibility_rounded, color: Colors.white),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@@ -123,34 +101,29 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => SpectatorScreen(
|
builder: (context) => SpectatorScreen(
|
||||||
selectedLanguage: _selectedLanguage,
|
selectedLanguage: settings.language,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Padding(
|
],
|
||||||
padding: const EdgeInsets.only(right: 16.0),
|
|
||||||
child: Center(
|
|
||||||
child: Text(
|
|
||||||
'V1.2',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.grey[400],
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
backgroundColor: settings.backgroundColor,
|
||||||
|
body: _page(_selected),
|
||||||
|
bottomNavigationBar: BottomNavBar(
|
||||||
|
selectedIndex: tabs.indexOf(_selected),
|
||||||
|
onItemTapped: (i) => _onTabTapped(tabs[i]),
|
||||||
|
items: [
|
||||||
|
for (final tab in tabs)
|
||||||
|
BottomNavigationBarItem(
|
||||||
|
icon: Icon(_icons[tab]),
|
||||||
|
label: settings.t(_titles[tab]!),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
backgroundColor: _backgroundColor,
|
);
|
||||||
body: _pages[_selectedIndex],
|
},
|
||||||
bottomNavigationBar: BottomNavBar(
|
|
||||||
selectedIndex: _selectedIndex,
|
|
||||||
onItemTapped: _onItemTapped,
|
|
||||||
selectedLanguage: _selectedLanguage,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,232 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:google_sign_in/google_sign_in.dart';
|
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
import '../widgets/input_field.dart';
|
|
||||||
import 'home_screen.dart';
|
|
||||||
import 'register_screen.dart';
|
|
||||||
|
|
||||||
class LoginScreen extends StatefulWidget {
|
|
||||||
const LoginScreen({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<LoginScreen> createState() => _LoginScreenState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _LoginScreenState extends State<LoginScreen> {
|
|
||||||
final usernameController = TextEditingController();
|
|
||||||
final passwordController = TextEditingController();
|
|
||||||
bool rememberMe = false;
|
|
||||||
|
|
||||||
final GoogleSignIn _googleSignIn = GoogleSignIn(
|
|
||||||
clientId: 'YOUR_WEB_CLIENT_ID_HERE',
|
|
||||||
scopes: ['email'],
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_checkAutoLogin();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _checkAutoLogin() async {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
final isRemembered = prefs.getBool('rememberMe') ?? false;
|
|
||||||
final googleUser = prefs.getString('googleUser');
|
|
||||||
|
|
||||||
if (isRemembered) {
|
|
||||||
final savedUsername = prefs.getString('loginUsername') ?? prefs.getString('username');
|
|
||||||
final savedPassword = prefs.getString('password');
|
|
||||||
if (savedUsername != null && savedPassword != null) {
|
|
||||||
usernameController.text = savedUsername;
|
|
||||||
passwordController.text = savedPassword;
|
|
||||||
setState(() => rememberMe = true);
|
|
||||||
}
|
|
||||||
} else if (googleUser != null) {
|
|
||||||
Navigator.pushReplacement(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (context) => const HomeScreen()),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _saveLoginDetails(String username, String password) async {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
await prefs.setString('loginUsername', username); // Ensures login uses latest username
|
|
||||||
await prefs.setString('password', password);
|
|
||||||
|
|
||||||
if (rememberMe) {
|
|
||||||
await prefs.setBool('rememberMe', true);
|
|
||||||
} else {
|
|
||||||
await prefs.remove('rememberMe');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void login() async {
|
|
||||||
String username = usernameController.text.trim();
|
|
||||||
String password = passwordController.text.trim();
|
|
||||||
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
String? savedUsername = prefs.getString('loginUsername') ?? prefs.getString('username'); // Get the latest username
|
|
||||||
String? savedPassword = prefs.getString('password'); // Get the saved password
|
|
||||||
|
|
||||||
if (savedUsername == username && savedPassword == password) {
|
|
||||||
await _saveLoginDetails(username, password);
|
|
||||||
Navigator.pushReplacement(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (context) => const HomeScreen()),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(content: Text('Invalid username or password')),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Future<void> googleLogin() async {
|
|
||||||
try {
|
|
||||||
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
|
|
||||||
if (googleUser != null) {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
await prefs.setString('googleUser', googleUser.displayName ?? 'Google User');
|
|
||||||
await prefs.setString('googleEmail', googleUser.email);
|
|
||||||
|
|
||||||
Navigator.pushReplacement(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (context) => const HomeScreen()),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(content: Text('Google Sign-In Failed: $error')),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
body: Center(
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
padding: const EdgeInsets.all(24),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Image.asset(
|
|
||||||
'assets/logo.png',
|
|
||||||
width: 1000,
|
|
||||||
height: 150,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 40),
|
|
||||||
InputField(
|
|
||||||
hintText: 'Username',
|
|
||||||
icon: Icons.person,
|
|
||||||
controller: usernameController,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
InputField(
|
|
||||||
hintText: 'Password',
|
|
||||||
icon: Icons.lock,
|
|
||||||
obscureText: true,
|
|
||||||
controller: passwordController,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
/// Remember Me Checkbox - Centered
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Checkbox(
|
|
||||||
value: rememberMe,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
rememberMe = value ?? false;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
activeColor: Colors.grey[800],
|
|
||||||
),
|
|
||||||
const Text(
|
|
||||||
'Remember Me',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.black87,
|
|
||||||
fontSize: 16,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
|
|
||||||
/// Login Button
|
|
||||||
ElevatedButton(
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.grey[800],
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
minimumSize: const Size.fromHeight(50),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: login,
|
|
||||||
child: const Text('Login', style: TextStyle(fontSize: 18)),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
/// Horizontal Line with "or"
|
|
||||||
Row(
|
|
||||||
children: const [
|
|
||||||
Expanded(
|
|
||||||
child: Divider(color: Colors.grey, thickness: 1),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
|
||||||
child: Text("or", style: TextStyle(color: Colors.grey, fontSize: 16)),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Divider(color: Colors.grey, thickness: 1),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
/// Google Sign-In Button (Styled same as Login)
|
|
||||||
ElevatedButton.icon(
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.grey[800], // Match Login Button
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
minimumSize: const Size.fromHeight(50),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: googleLogin,
|
|
||||||
icon: const Icon(Icons.g_mobiledata, size: 30), // Google Icon
|
|
||||||
label: const Text('Sign in with Google', style: TextStyle(fontSize: 18)),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
|
|
||||||
/// Register Text (Styled in Blue)
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (context) => const RegisterScreen()),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: const Text(
|
|
||||||
"Don't have an account? Register",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Colors.grey, // Better visibility
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+67
-212
@@ -1,6 +1,8 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import '../utils/target_colors.dart';
|
||||||
|
import '../theme/app_theme.dart';
|
||||||
import 'package:flutter/services.dart' show rootBundle;
|
import 'package:flutter/services.dart' show rootBundle;
|
||||||
import 'package:image/image.dart' as img;
|
import 'package:image/image.dart' as img;
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
@@ -273,121 +275,9 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
"📏 Scale factors calculated: X=$_scaleFactorX, Y=$_scaleFactorY");
|
"📏 Scale factors calculated: X=$_scaleFactorX, Y=$_scaleFactorY");
|
||||||
}
|
}
|
||||||
|
|
||||||
Color _getBackgroundColorForTarget(String targetPath) {
|
// One source of truth for target colors (utils/target_colors.dart)
|
||||||
// Map each target to its background color (extracted from first pixel of each image)
|
Color _getBackgroundColorForTarget(String targetPath) =>
|
||||||
switch (targetPath) {
|
TargetColors.getBackgroundColor(targetPath);
|
||||||
case 'assets/target.png':
|
|
||||||
return const Color(0xFFFFFFFF); // White
|
|
||||||
|
|
||||||
case 'assets/targets/Target1.jpg':
|
|
||||||
return const Color(0xFFE8ECD5); // Light beige
|
|
||||||
|
|
||||||
case 'assets/targets/Target2.jpg':
|
|
||||||
return const Color(0xFFC1DF87); // Light green
|
|
||||||
|
|
||||||
case 'assets/targets/Target3.jpg':
|
|
||||||
return const Color(0xFFFEFEFE); // Off-white
|
|
||||||
|
|
||||||
case 'assets/targets/Target4.jpg':
|
|
||||||
return const Color(0xFFD42931); // Red
|
|
||||||
|
|
||||||
case 'assets/targets/Target5.jpg':
|
|
||||||
return const Color(0xFF02050A); // Very dark blue/black
|
|
||||||
|
|
||||||
case 'assets/targets/Target6.jpg':
|
|
||||||
return const Color(0xFFF3E7D1); // Light beige
|
|
||||||
|
|
||||||
case 'assets/targets/Target7.jpg':
|
|
||||||
return const Color(0xFFFFD454); // Bright yellow
|
|
||||||
|
|
||||||
case 'assets/targets/Target8.jpg':
|
|
||||||
return const Color(0xFF1E5E81); // Dark teal blue
|
|
||||||
|
|
||||||
case 'assets/targets/Target9.jpg':
|
|
||||||
return const Color(0xFFFEFEFC); // Off-white
|
|
||||||
|
|
||||||
case 'assets/targets/Target10.jpg':
|
|
||||||
return const Color(0xFF98926E); // Olive green
|
|
||||||
|
|
||||||
case 'assets/targets/Target11.jpg':
|
|
||||||
return const Color(0xFF13132B); // Dark blue
|
|
||||||
|
|
||||||
case 'assets/targets/Target12.jpg':
|
|
||||||
return const Color(0xFFF5F4EF); // Off-white
|
|
||||||
|
|
||||||
case 'assets/targets/Target13.jpg':
|
|
||||||
return const Color(0xFF174AA5); // Blue
|
|
||||||
|
|
||||||
case 'assets/targets/Target14.jpg':
|
|
||||||
return const Color(0xFFFEE05E); // Light yellow
|
|
||||||
|
|
||||||
case 'assets/targets/Target15.jpg':
|
|
||||||
return const Color(0xFFFFFFFF); // White
|
|
||||||
|
|
||||||
case 'assets/targets/Target16.jpg':
|
|
||||||
return const Color(0xFF000000); // Black
|
|
||||||
|
|
||||||
case 'assets/targets/Target17.jpg':
|
|
||||||
return const Color(0xFF21304D); // Dark blue
|
|
||||||
|
|
||||||
case 'assets/targets/Target18.jpg':
|
|
||||||
return const Color(0xFF050608); // Very dark gray
|
|
||||||
|
|
||||||
case 'assets/targets/Target19.jpg':
|
|
||||||
return const Color(0xFFF68527); // Warm orange
|
|
||||||
|
|
||||||
case 'assets/targets/Target20.jpg':
|
|
||||||
return const Color(0xFFA9D9EF); // Light blue
|
|
||||||
|
|
||||||
case 'assets/targets/Target21.jpg':
|
|
||||||
return const Color(0xFFDA6868); // Muted red
|
|
||||||
|
|
||||||
case 'assets/targets/Target22.jpg':
|
|
||||||
return const Color(0xFFFBFAF6); // Off-white
|
|
||||||
|
|
||||||
case 'assets/targets/Target23.jpg':
|
|
||||||
return const Color(0xFF000000); // Black
|
|
||||||
|
|
||||||
case 'assets/targets/Target24.jpg':
|
|
||||||
return const Color(0xFFb7b7b7); // Gray
|
|
||||||
|
|
||||||
case 'assets/targets/Target25.jpg':
|
|
||||||
return const Color(0xFF040308); // Very dark gray
|
|
||||||
|
|
||||||
case 'assets/targets/Target26.jpg':
|
|
||||||
return const Color(0xFF161C2C); // Dark blue-gray
|
|
||||||
|
|
||||||
case 'assets/targets/Target27.jpg':
|
|
||||||
return const Color(0xFF28A5DF); // Blue
|
|
||||||
|
|
||||||
case 'assets/targets/Target28.jpg':
|
|
||||||
return const Color(0xFFFFFFFF); // White
|
|
||||||
|
|
||||||
case 'assets/targets/Target29.jpg':
|
|
||||||
return const Color(0xFF180E27); // Dark purple
|
|
||||||
|
|
||||||
case 'assets/targets/Target30.jpg':
|
|
||||||
return const Color(0xFFFDFDFB); // Off-white
|
|
||||||
|
|
||||||
case 'assets/targets/Target31.jpg':
|
|
||||||
return const Color(0xFFC52736); // Red
|
|
||||||
|
|
||||||
case 'assets/targets/Target32.jpg':
|
|
||||||
return const Color(0xFFFCF3EE); // Light cream
|
|
||||||
|
|
||||||
case 'assets/targets/Target33.jpg':
|
|
||||||
return const Color(0xFFFCFCF3); // Very light off-white
|
|
||||||
|
|
||||||
case 'assets/targets/Target34.jpg':
|
|
||||||
return const Color(0xFFFFFFFD); // Almost white
|
|
||||||
|
|
||||||
case 'assets/targets/Target35.jpg':
|
|
||||||
return const Color(0xFFFFC5C4); // Light salmon
|
|
||||||
|
|
||||||
default:
|
|
||||||
return Colors.grey[900]!; // Fallback to dark gray
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _loadBulletColor() async {
|
Future<void> _loadBulletColor() async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
@@ -940,6 +830,7 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
final targetData = {
|
final targetData = {
|
||||||
'date': dateString,
|
'date': dateString,
|
||||||
'totalScore': _totalScore,
|
'totalScore': _totalScore,
|
||||||
|
'bulletCount': widget.bulletCount, // shots fired; missed ones are absent from 'bullets'
|
||||||
'bullets': bulletsInDefaultCoordinates,
|
'bullets': bulletsInDefaultCoordinates,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1349,7 +1240,7 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
children: [
|
children: [
|
||||||
// Training/Tournament Banner
|
// Training/Tournament Banner
|
||||||
Container(
|
Container(
|
||||||
color: Colors.grey[300],
|
color: Surfaces.current.card,
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 16, vertical: 10),
|
horizontal: 16, vertical: 10),
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -1359,9 +1250,9 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
child: Text(
|
child: Text(
|
||||||
_currentFolderName.isNotEmpty
|
_currentFolderName.isNotEmpty
|
||||||
? _currentFolderName
|
? _currentFolderName
|
||||||
: 'No training selected',
|
: _t('No training selected'),
|
||||||
style: const TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.black,
|
color: Surfaces.current.textPrimary,
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
@@ -1371,8 +1262,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
if (_currentDate.isNotEmpty)
|
if (_currentDate.isNotEmpty)
|
||||||
Text(
|
Text(
|
||||||
_currentDate,
|
_currentDate,
|
||||||
style: const TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.black,
|
color: Surfaces.current.textPrimary,
|
||||||
fontSize: 11,
|
fontSize: 11,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -1636,7 +1527,7 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
Container(
|
Container(
|
||||||
height: 30,
|
height: 30,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.grey[300],
|
color: Surfaces.current.card,
|
||||||
borderRadius:
|
borderRadius:
|
||||||
const BorderRadius
|
const BorderRadius
|
||||||
.only(
|
.only(
|
||||||
@@ -1649,11 +1540,11 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: Text(
|
child: Text(
|
||||||
'${index + 1}',
|
'${index + 1}',
|
||||||
style: const TextStyle(
|
style: TextStyle(
|
||||||
fontWeight:
|
fontWeight:
|
||||||
FontWeight.bold,
|
FontWeight.bold,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: Colors.black87,
|
color: Surfaces.current.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -1728,7 +1619,7 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
Container(
|
Container(
|
||||||
height: 30,
|
height: 30,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.grey[300],
|
color: Surfaces.current.card,
|
||||||
borderRadius:
|
borderRadius:
|
||||||
const BorderRadius
|
const BorderRadius
|
||||||
.only(
|
.only(
|
||||||
@@ -1741,11 +1632,11 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: Text(
|
child: Text(
|
||||||
'$bulletNum',
|
'$bulletNum',
|
||||||
style: const TextStyle(
|
style: TextStyle(
|
||||||
fontWeight:
|
fontWeight:
|
||||||
FontWeight.bold,
|
FontWeight.bold,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: Colors.black87,
|
color: Surfaces.current.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -1791,109 +1682,73 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
// Room for the save button, which sticks up out of the bottom bar
|
||||||
|
const SizedBox(height: 40),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
_buildEditController(),
|
_buildEditController(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
bottomNavigationBar: Column(
|
// Same layout as the camera screen: number on the left, round white
|
||||||
mainAxisSize: MainAxisSize.min,
|
// main action docked in the notch, secondary icons on the right.
|
||||||
children: [
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
||||||
// Top bar - Total Score
|
floatingActionButton: FloatingActionButton(
|
||||||
Container(
|
backgroundColor: Colors.white,
|
||||||
color: Colors.grey[300],
|
onPressed: _saveToLastFolder,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
tooltip: _t("Save"),
|
||||||
child: Row(
|
child: const Icon(Icons.save, color: Colors.black),
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.track_changes, size: 20, color: Colors.black),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
_t("Total score:"),
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.black,
|
|
||||||
),
|
),
|
||||||
),
|
bottomNavigationBar: BottomAppBar(
|
||||||
const SizedBox(width: 12),
|
|
||||||
Text(
|
|
||||||
"$_totalScore",
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.black,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// Bottom bar - Action Buttons
|
|
||||||
BottomAppBar(
|
|
||||||
color: Colors.grey[900],
|
color: Colors.grey[900],
|
||||||
padding: EdgeInsets.zero,
|
shape: const CircularNotchedRectangle(),
|
||||||
|
notchMargin: 8.0,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 60,
|
height: 60,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
// Plus button (left, no background)
|
// Left - total score
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Center(
|
child: Padding(
|
||||||
child: IconButton(
|
padding: const EdgeInsets.only(left: 16),
|
||||||
icon: Stack(
|
child: Column(
|
||||||
alignment: Alignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.folder, color: Colors.white, size: 24),
|
Text(
|
||||||
Positioned(
|
_t('Total').toUpperCase(),
|
||||||
bottom: 0,
|
style: const TextStyle(
|
||||||
right: 0,
|
fontSize: 10,
|
||||||
child: Container(
|
fontWeight: FontWeight.bold,
|
||||||
decoration: const BoxDecoration(
|
letterSpacing: 1.2,
|
||||||
color: Colors.white,
|
color: Colors.white54,
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.all(2),
|
),
|
||||||
child: const Icon(Icons.add, color: Colors.grey, size: 10),
|
Text(
|
||||||
|
'$_totalScore',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 24,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.white,
|
||||||
|
height: 1.1,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Center space for FAB
|
||||||
|
const SizedBox(width: 80),
|
||||||
|
// Right - save to another folder, edit mode
|
||||||
|
Expanded(
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.create_new_folder_outlined, color: Colors.white, size: 24),
|
||||||
onPressed: _saveTargetDataWithDialog,
|
onPressed: _saveTargetDataWithDialog,
|
||||||
|
tooltip: _t("Save to folder"),
|
||||||
),
|
),
|
||||||
),
|
IconButton(
|
||||||
),
|
|
||||||
// Save button (center with white background)
|
|
||||||
Expanded(
|
|
||||||
child: Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
||||||
child: SizedBox(
|
|
||||||
width: 60,
|
|
||||||
height: 40,
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
child: Material(
|
|
||||||
color: Colors.transparent,
|
|
||||||
child: InkWell(
|
|
||||||
onTap: _saveToLastFolder,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
child: const Icon(Icons.save,
|
|
||||||
color: Colors.black, size: 20),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// Edit button (right)
|
|
||||||
Expanded(
|
|
||||||
child: Center(
|
|
||||||
child: IconButton(
|
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
_isEditMode ? Icons.check : Icons.edit,
|
_isEditMode ? Icons.check : Icons.edit,
|
||||||
color: _isEditMode ? Colors.red : Colors.white,
|
color: _isEditMode ? Colors.red : Colors.white,
|
||||||
@@ -1907,14 +1762,14 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
},
|
},
|
||||||
tooltip: _isEditMode ? _t("Done Editing") : _t("Edit Mode"),
|
tooltip: _isEditMode ? _t("Done Editing") : _t("Edit Mode"),
|
||||||
),
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,180 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
import '../widgets/input_field.dart';
|
|
||||||
import 'login_screen.dart';
|
|
||||||
|
|
||||||
class RegisterScreen extends StatefulWidget {
|
|
||||||
const RegisterScreen({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<RegisterScreen> createState() => _RegisterScreenState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _RegisterScreenState extends State<RegisterScreen> {
|
|
||||||
final usernameController = TextEditingController();
|
|
||||||
final emailController = TextEditingController();
|
|
||||||
final passwordController = TextEditingController();
|
|
||||||
final confirmPasswordController = TextEditingController();
|
|
||||||
|
|
||||||
Future<void> register() async {
|
|
||||||
String username = usernameController.text.trim();
|
|
||||||
String email = emailController.text.trim();
|
|
||||||
String password = passwordController.text.trim();
|
|
||||||
String confirmPassword = confirmPasswordController.text.trim();
|
|
||||||
|
|
||||||
if (username.isEmpty || email.isEmpty || password.isEmpty || confirmPassword.isEmpty) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(content: Text('All fields are required')),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!RegExp(r'^[^@]+@[^@]+\.[^@]+').hasMatch(email)) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(content: Text('Invalid email format')),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (password != confirmPassword) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(content: Text('Passwords do not match')),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
|
|
||||||
// Check if the username or email is already taken
|
|
||||||
String? existingUser = prefs.getString(username);
|
|
||||||
String? existingEmail = prefs.getString(email);
|
|
||||||
if (existingUser != null || existingEmail != null) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(content: Text('Username or Email already exists. Choose another.')),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save user credentials in SharedPreferences
|
|
||||||
await prefs.setString(username, password);
|
|
||||||
await prefs.setString(email, username); // Store email linked to the username
|
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(content: Text('Registration Successful! Please Login')),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Redirect to Login Screen
|
|
||||||
Navigator.pushReplacement(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (context) => const LoginScreen()),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
body: Center(
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
padding: const EdgeInsets.all(24),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
/// Logo
|
|
||||||
Image.asset(
|
|
||||||
'assets/logo.png',
|
|
||||||
width: 1000,
|
|
||||||
height: 150,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 40),
|
|
||||||
|
|
||||||
/// Username Field
|
|
||||||
InputField(
|
|
||||||
hintText: 'Username',
|
|
||||||
icon: Icons.person,
|
|
||||||
controller: usernameController,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
/// Email Field
|
|
||||||
InputField(
|
|
||||||
hintText: 'Email',
|
|
||||||
icon: Icons.email,
|
|
||||||
controller: emailController,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
/// Password Field
|
|
||||||
InputField(
|
|
||||||
hintText: 'Password',
|
|
||||||
icon: Icons.lock,
|
|
||||||
obscureText: true,
|
|
||||||
controller: passwordController,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
/// Confirm Password Field
|
|
||||||
InputField(
|
|
||||||
hintText: 'Confirm Password',
|
|
||||||
icon: Icons.lock,
|
|
||||||
obscureText: true,
|
|
||||||
controller: confirmPasswordController,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
|
|
||||||
/// Register Button
|
|
||||||
ElevatedButton(
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.grey[800], // Match Login Button
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
minimumSize: const Size.fromHeight(50),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: register,
|
|
||||||
child: const Text('Register', style: TextStyle(fontSize: 18)),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
/// Horizontal Line with "or" (optional, in case Google Sign-Up is added)
|
|
||||||
Row(
|
|
||||||
children: const [
|
|
||||||
Expanded(
|
|
||||||
child: Divider(color: Colors.grey, thickness: 1),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
|
||||||
child: Text("or", style: TextStyle(color: Colors.grey, fontSize: 16)),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Divider(color: Colors.grey, thickness: 1),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
/// Login Navigation (Styled in Blue)
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
Navigator.pushReplacement(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (context) => const LoginScreen()),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: const Text(
|
|
||||||
"Already have an account? Login",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Colors.grey, // Styled for better visibility
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,252 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import '../services/app_settings.dart';
|
||||||
|
import '../services/target_repository.dart';
|
||||||
|
import '../theme/app_theme.dart';
|
||||||
|
import '../widgets/section.dart';
|
||||||
|
import 'target_view.dart';
|
||||||
|
|
||||||
|
/// One training or tournament: its stats, its targets, and edit/delete actions.
|
||||||
|
class SessionScreen extends StatefulWidget {
|
||||||
|
final Session session;
|
||||||
|
|
||||||
|
const SessionScreen({super.key, required this.session});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SessionScreen> createState() => _SessionScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SessionScreenState extends State<SessionScreen> {
|
||||||
|
late Session _session = widget.session;
|
||||||
|
|
||||||
|
Future<void> _reload() async {
|
||||||
|
final sessions = await TargetRepository.loadSessions();
|
||||||
|
final updated = sessions.where((s) => s.name == _session.name);
|
||||||
|
if (!mounted) return;
|
||||||
|
if (updated.isEmpty) {
|
||||||
|
Navigator.pop(context); // session no longer exists
|
||||||
|
} else {
|
||||||
|
setState(() => _session = updated.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _openTargets(List<TargetRecord> targets) {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (_) => TargetViewScreen(
|
||||||
|
jsonFiles: [for (final t in targets) t.file],
|
||||||
|
refreshFolders: _reload,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _edit() async {
|
||||||
|
final result = await showEditSessionDialog(context, _session);
|
||||||
|
if (result == null) return;
|
||||||
|
final ok = await TargetRepository.updateSession(_session, name: result.name, isTournament: result.isTournament);
|
||||||
|
if (!mounted) return;
|
||||||
|
if (!ok) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text(AppSettings.instance.t('A folder with this name already exists'))),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_session = Session(name: result.name, isTournament: result.isTournament, date: _session.date, targets: _session.targets);
|
||||||
|
_reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _delete() async {
|
||||||
|
final s = AppSettings.instance;
|
||||||
|
final message = '${s.t('Are you sure you want to delete the folder')} "${_session.name}" ${s.t('and all of its contents?')}';
|
||||||
|
if (await confirmDelete(context, message) != true) return;
|
||||||
|
await TargetRepository.deleteSession(_session);
|
||||||
|
if (mounted) Navigator.pop(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _deleteTarget(TargetRecord target) async {
|
||||||
|
if (await confirmDelete(context, AppSettings.instance.t('Are you sure you want to delete this file?')) != true) return;
|
||||||
|
await TargetRepository.deleteTarget(target);
|
||||||
|
_reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ListenableBuilder(
|
||||||
|
listenable: AppSettings.instance,
|
||||||
|
builder: (context, _) {
|
||||||
|
final s = AppSettings.instance;
|
||||||
|
final t = s.t;
|
||||||
|
final surf = Surfaces.current;
|
||||||
|
final session = _session;
|
||||||
|
final stats = ShooterStats.of([session]);
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: s.backgroundColor,
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(session.name, style: const TextStyle(color: Colors.white)),
|
||||||
|
backgroundColor: AppTheme.bar,
|
||||||
|
iconTheme: const IconThemeData(color: Colors.white),
|
||||||
|
scrolledUnderElevation: 0,
|
||||||
|
actions: [
|
||||||
|
IconButton(icon: const Icon(Icons.edit), tooltip: t('Edit'), onPressed: _edit),
|
||||||
|
IconButton(icon: const Icon(Icons.delete, color: Colors.red), tooltip: t('Delete'), onPressed: _delete),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: ListView(
|
||||||
|
// Keep the last row clear of the system gesture bar (edge-to-edge)
|
||||||
|
padding: EdgeInsets.fromLTRB(16, 4, 16, 24 + MediaQuery.paddingOf(context).bottom),
|
||||||
|
children: [
|
||||||
|
SectionHeader(
|
||||||
|
'${session.isTournament ? t('Tournament') : t('Training')} · ${DateFormat('d. M. yyyy').format(session.date)}',
|
||||||
|
),
|
||||||
|
StatGrid(tiles: [
|
||||||
|
StatTile(label: t('Total'), value: '${session.totalScore}', caption: targetCount(session.targets.length)),
|
||||||
|
StatTile(
|
||||||
|
label: t('Average per shot'),
|
||||||
|
value: stats.averagePerShot?.toStringAsFixed(2) ?? '–',
|
||||||
|
caption: shotCount(stats.shots),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
SectionHeader(t('Targets')),
|
||||||
|
if (session.targets.isEmpty)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Text(t('No targets in this folder'), style: TextStyle(color: surf.textSecondary)),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
GroupCard(children: [
|
||||||
|
for (int i = 0; i < session.targets.length; i++)
|
||||||
|
SettingsTile(
|
||||||
|
title: '${t('Target')} ${i + 1}',
|
||||||
|
subtitle: '${DateFormat('HH:mm').format(session.targets[i].shotAt)} · ${shotCount(session.targets[i].shots)}',
|
||||||
|
onTap: () => _openTargets([session.targets[i]]),
|
||||||
|
trailing: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'${session.targets[i].score}',
|
||||||
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: surf.textPrimary),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.delete, color: Colors.red, size: 20),
|
||||||
|
onPressed: () => _deleteTarget(session.targets[i]),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// "1 target" / "5 targets", with Slovenian dual and plural forms.
|
||||||
|
String targetCount(int n) {
|
||||||
|
final s = AppSettings.instance;
|
||||||
|
if (s.language != 'Slovenian') return n == 1 ? '1 target' : '$n targets';
|
||||||
|
final mod = n % 100;
|
||||||
|
final word = mod == 1 ? 'tarča' : mod == 2 ? 'tarči' : (mod == 3 || mod == 4) ? 'tarče' : 'tarč';
|
||||||
|
return '$n $word';
|
||||||
|
}
|
||||||
|
|
||||||
|
/// "1 shot" / "5 shots", with Slovenian dual and plural forms.
|
||||||
|
String shotCount(int n) {
|
||||||
|
final s = AppSettings.instance;
|
||||||
|
if (s.language != 'Slovenian') return n == 1 ? '1 shot' : '$n shots';
|
||||||
|
final mod = n % 100;
|
||||||
|
final word = mod == 1 ? 'strel' : mod == 2 ? 'strela' : (mod == 3 || mod == 4) ? 'streli' : 'strelov';
|
||||||
|
return '$n $word';
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool?> confirmDelete(BuildContext context, String message) {
|
||||||
|
final s = AppSettings.instance;
|
||||||
|
return showDialog<bool>(
|
||||||
|
context: context,
|
||||||
|
builder: (dialog) => AlertDialog(
|
||||||
|
title: Text(s.t('Confirm Deletion')),
|
||||||
|
content: Text(message),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(dialog, false),
|
||||||
|
child: Text(s.t('Cancel'), style: const TextStyle(color: Colors.white70)),
|
||||||
|
),
|
||||||
|
FilledButton(
|
||||||
|
style: FilledButton.styleFrom(backgroundColor: Colors.red[700]),
|
||||||
|
onPressed: () => Navigator.pop(dialog, true),
|
||||||
|
child: Text(s.t('Yes, delete')),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class SessionEdit {
|
||||||
|
final String name;
|
||||||
|
final bool isTournament;
|
||||||
|
|
||||||
|
const SessionEdit(this.name, this.isTournament);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Rename a session and choose training/tournament.
|
||||||
|
Future<SessionEdit?> showEditSessionDialog(BuildContext context, Session session) {
|
||||||
|
final s = AppSettings.instance;
|
||||||
|
final controller = TextEditingController(text: session.name);
|
||||||
|
var isTournament = session.isTournament;
|
||||||
|
|
||||||
|
return showDialog<SessionEdit>(
|
||||||
|
context: context,
|
||||||
|
builder: (dialog) => StatefulBuilder(
|
||||||
|
builder: (context, setDialogState) => AlertDialog(
|
||||||
|
title: Text(s.t('Folder Settings')),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
TextField(
|
||||||
|
controller: controller,
|
||||||
|
style: const TextStyle(color: Colors.white),
|
||||||
|
cursorColor: s.bulletColor,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
filled: true,
|
||||||
|
fillColor: Colors.white10,
|
||||||
|
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: s.bulletColor),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
SwitchListTile(
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
title: Text(s.t('Tournament'), style: const TextStyle(color: Colors.white)),
|
||||||
|
secondary: Icon(Icons.emoji_events, color: isTournament ? s.bulletColor : Colors.white54),
|
||||||
|
value: isTournament,
|
||||||
|
activeTrackColor: s.bulletColor,
|
||||||
|
onChanged: (v) => setDialogState(() => isTournament = v),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(dialog),
|
||||||
|
child: Text(s.t('Cancel'), style: const TextStyle(color: Colors.white70)),
|
||||||
|
),
|
||||||
|
FilledButton(
|
||||||
|
style: FilledButton.styleFrom(backgroundColor: s.bulletColor),
|
||||||
|
onPressed: () {
|
||||||
|
final name = controller.text.trim();
|
||||||
|
if (name.isEmpty || name.contains('/')) return;
|
||||||
|
Navigator.pop(dialog, SessionEdit(name, isTournament));
|
||||||
|
},
|
||||||
|
child: Text(s.t('Save')),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
+369
-1236
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_mjpeg/flutter_mjpeg.dart';
|
import 'package:flutter_mjpeg/flutter_mjpeg.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import '../utils/translations.dart';
|
import '../utils/translations.dart';
|
||||||
|
import '../services/wifi_binding.dart';
|
||||||
|
|
||||||
class SpectatorScreen extends StatefulWidget {
|
class SpectatorScreen extends StatefulWidget {
|
||||||
final String selectedLanguage;
|
final String selectedLanguage;
|
||||||
@@ -20,18 +21,28 @@ class _SpectatorScreenState extends State<SpectatorScreen> {
|
|||||||
List<bool> _enabledCameras = List.generate(6, (_) => false); // Which cameras have IPs configured
|
List<bool> _enabledCameras = List.generate(6, (_) => false); // Which cameras have IPs configured
|
||||||
List<Map<String, dynamic>> _cameras = [];
|
List<Map<String, dynamic>> _cameras = [];
|
||||||
Color _bulletColor = Colors.blue; // default/fallback bullet color
|
Color _bulletColor = Colors.blue; // default/fallback bullet color
|
||||||
|
late final Future<void> _wifiReady;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_wifiReady = WifiBinding.acquire();
|
||||||
_loadCameras();
|
_loadCameras();
|
||||||
_loadBulletColor();
|
_loadBulletColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
WifiBinding.release();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
String _t(String key) {
|
String _t(String key) {
|
||||||
return AppTranslations.translate(key, widget.selectedLanguage);
|
return AppTranslations.translate(key, widget.selectedLanguage);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadCameras() async {
|
Future<void> _loadCameras() async {
|
||||||
|
await _wifiReady; // streams must start after traffic is pinned to Wi-Fi
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
List<Map<String, dynamic>> cameras = [];
|
List<Map<String, dynamic>> cameras = [];
|
||||||
List<bool> enabledCameras = List.generate(6, (_) => false);
|
List<bool> enabledCameras = List.generate(6, (_) => false);
|
||||||
|
|||||||
+73
-428
@@ -12,41 +12,34 @@ import 'yolo_detector.dart';
|
|||||||
import 'preview_screen.dart';
|
import 'preview_screen.dart';
|
||||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||||
import '../utils/translations.dart';
|
import '../utils/translations.dart';
|
||||||
|
import '../widgets/camera_sheet.dart';
|
||||||
|
import '../widgets/image_settings.dart';
|
||||||
|
import '../services/wifi_binding.dart';
|
||||||
|
|
||||||
enum ImageFilterType { none, greyscale, invert }
|
// Top-level: runs in background isolate via compute().
|
||||||
|
// Crops the capture to a square; filters are already baked into the screenshot.
|
||||||
// Top-level: runs in background isolate via compute()
|
Uint8List _processStreamImage(Uint8List bytes) {
|
||||||
Uint8List _processStreamImage(List<dynamic> args) {
|
|
||||||
final bytes = args[0] as Uint8List;
|
|
||||||
final filter = args[1] as int; // ImageFilterType.index
|
|
||||||
final decoded = img.decodeImage(bytes)!;
|
final decoded = img.decodeImage(bytes)!;
|
||||||
final w = decoded.width, h = decoded.height;
|
final w = decoded.width, h = decoded.height;
|
||||||
final size = w < h ? w : h;
|
final size = w < h ? w : h;
|
||||||
img.Image cropped = img.copyCrop(decoded,
|
final cropped = img.copyCrop(decoded,
|
||||||
x: (w - size) ~/ 2, y: (h - size) ~/ 2, width: size, height: size);
|
x: (w - size) ~/ 2, y: (h - size) ~/ 2, width: size, height: size);
|
||||||
img.Image processed;
|
return Uint8List.fromList(img.encodeJpg(cropped));
|
||||||
if (filter == ImageFilterType.greyscale.index) {
|
|
||||||
processed = img.grayscale(cropped);
|
|
||||||
} else if (filter == ImageFilterType.invert.index) {
|
|
||||||
final result = img.Image.from(cropped);
|
|
||||||
for (int y = 0; y < result.height; y++) {
|
|
||||||
for (int x = 0; x < result.width; x++) {
|
|
||||||
final p = result.getPixel(x, y);
|
|
||||||
result.setPixelRgb(
|
|
||||||
x, y, 255 - p.r.toInt(), 255 - p.g.toInt(), 255 - p.b.toInt());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
processed = result;
|
|
||||||
} else {
|
|
||||||
processed = cropped;
|
|
||||||
}
|
|
||||||
return Uint8List.fromList(img.encodeJpg(processed));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class CameraStreamScreen extends StatefulWidget {
|
class CameraStreamScreen extends StatefulWidget {
|
||||||
final int cameraIndex;
|
final int cameraIndex; // shooting position 1–6
|
||||||
|
final String? ip; // chosen camera; falls back to the saved IP of the position
|
||||||
|
final String? location; // strelišče the camera belongs to
|
||||||
|
|
||||||
const CameraStreamScreen({super.key, required this.cameraIndex});
|
const CameraStreamScreen(
|
||||||
|
{super.key, required this.cameraIndex, this.ip, this.location});
|
||||||
|
|
||||||
|
// Image settings are kept per camera, i.e. per position and location
|
||||||
|
String get settingsId =>
|
||||||
|
location == null ? '$cameraIndex' : '${cameraIndex}_$location';
|
||||||
|
String get title =>
|
||||||
|
location == null ? '$cameraIndex' : '$cameraIndex · $location';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<CameraStreamScreen> createState() => _CameraStreamScreenState();
|
State<CameraStreamScreen> createState() => _CameraStreamScreenState();
|
||||||
@@ -60,15 +53,11 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
final ScreenshotController _screenshotController = ScreenshotController();
|
final ScreenshotController _screenshotController = ScreenshotController();
|
||||||
final TransformationController _transformationController =
|
final TransformationController _transformationController =
|
||||||
TransformationController();
|
TransformationController();
|
||||||
ImageFilterType _selectedFilter = ImageFilterType.none;
|
ImageAdjustments _image = const ImageAdjustments();
|
||||||
|
|
||||||
late YOLODetector _yoloDetector;
|
late YOLODetector _yoloDetector;
|
||||||
int _numberOfBullets = 5;
|
int _numberOfBullets = 5;
|
||||||
|
|
||||||
// Brightness and contrast controls
|
|
||||||
double _brightness = 0.0;
|
|
||||||
double _contrast = 1.0;
|
|
||||||
|
|
||||||
late AnimationController _zoomAnimController;
|
late AnimationController _zoomAnimController;
|
||||||
Animation<Matrix4>? _zoomAnimation;
|
Animation<Matrix4>? _zoomAnimation;
|
||||||
Matrix4? _originalMatrix;
|
Matrix4? _originalMatrix;
|
||||||
@@ -121,10 +110,13 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
bool _reloadEnabled = false;
|
bool _reloadEnabled = false;
|
||||||
bool _waitEnabled = false;
|
bool _waitEnabled = false;
|
||||||
|
|
||||||
|
late final Future<void> _wifiReady;
|
||||||
|
|
||||||
Future<void> _loadAllPrefs() async {
|
Future<void> _loadAllPrefs() async {
|
||||||
|
await _wifiReady; // stream must start after traffic is pinned to Wi-Fi
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
final filterIndex = prefs.getInt('selectedFilter');
|
final image = await ImageAdjustments.load(widget.settingsId);
|
||||||
final url = prefs.getString('cameraIP_${widget.cameraIndex}');
|
final url = widget.ip ?? prefs.getString('cameraIP_${widget.cameraIndex}');
|
||||||
final streamUrl = (url != null && url.trim().isNotEmpty)
|
final streamUrl = (url != null && url.trim().isNotEmpty)
|
||||||
? (url.startsWith(RegExp(r"https?://")) ? url : "http://$url")
|
? (url.startsWith(RegExp(r"https?://")) ? url : "http://$url")
|
||||||
: null;
|
: null;
|
||||||
@@ -137,15 +129,9 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
setState(() {
|
setState(() {
|
||||||
_selectedLanguage = prefs.getString('language') ?? 'English';
|
_selectedLanguage = prefs.getString('language') ?? 'English';
|
||||||
_numberOfBullets = prefs.getInt('bulletCount') ?? 5;
|
_numberOfBullets = prefs.getInt('bulletCount') ?? 5;
|
||||||
_selectedFilter = (filterIndex != null &&
|
_image = image;
|
||||||
filterIndex >= 0 &&
|
|
||||||
filterIndex < ImageFilterType.values.length)
|
|
||||||
? ImageFilterType.values[filterIndex]
|
|
||||||
: ImageFilterType.none;
|
|
||||||
_bulletColor =
|
_bulletColor =
|
||||||
_getColorFromName(prefs.getString('bulletColor') ?? 'Blue');
|
_getColorFromName(prefs.getString('bulletColor') ?? 'Blue');
|
||||||
_brightness = prefs.getDouble('brightness') ?? 0.0;
|
|
||||||
_contrast = prefs.getDouble('contrast') ?? 1.0;
|
|
||||||
_streamUrl = streamUrl;
|
_streamUrl = streamUrl;
|
||||||
_isError = streamUrl == null;
|
_isError = streamUrl == null;
|
||||||
if (savedShoot != null) _shootSeconds = savedShoot;
|
if (savedShoot != null) _shootSeconds = savedShoot;
|
||||||
@@ -184,6 +170,7 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_wifiReady = WifiBinding.acquire();
|
||||||
_loadAllPrefs();
|
_loadAllPrefs();
|
||||||
|
|
||||||
YOLODetector.create().then((detector) => _yoloDetector = detector);
|
YOLODetector.create().then((detector) => _yoloDetector = detector);
|
||||||
@@ -218,12 +205,6 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _saveBrightnessContrast() async {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
await prefs.setDouble('brightness', _brightness);
|
|
||||||
await prefs.setDouble('contrast', _contrast);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color _getColorFromName(String colorName) {
|
Color _getColorFromName(String colorName) {
|
||||||
switch (colorName.toLowerCase()) {
|
switch (colorName.toLowerCase()) {
|
||||||
case 'blue':
|
case 'blue':
|
||||||
@@ -268,6 +249,8 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
statusBarIconBrightness: Brightness.light, // white icons
|
statusBarIconBrightness: Brightness.light, // white icons
|
||||||
systemNavigationBarColor: Colors.grey[900],
|
systemNavigationBarColor: Colors.grey[900],
|
||||||
systemNavigationBarIconBrightness: Brightness.light,
|
systemNavigationBarIconBrightness: Brightness.light,
|
||||||
|
// No grey scrim behind 3-button navigation; we paint the strip ourselves
|
||||||
|
systemNavigationBarContrastEnforced: false,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -282,7 +265,8 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
|
|
||||||
Future<void> _loadStreamUrl() async {
|
Future<void> _loadStreamUrl() async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
String? url = prefs.getString('cameraIP_${widget.cameraIndex}');
|
String? url =
|
||||||
|
widget.ip ?? prefs.getString('cameraIP_${widget.cameraIndex}');
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_streamUrl = (url != null && url.trim().isNotEmpty)
|
_streamUrl = (url != null && url.trim().isNotEmpty)
|
||||||
@@ -328,8 +312,7 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
final dir = await getApplicationDocumentsDirectory();
|
final dir = await getApplicationDocumentsDirectory();
|
||||||
final path = '${dir.path}/ip_capture_temp.jpg';
|
final path = '${dir.path}/ip_capture_temp.jpg';
|
||||||
|
|
||||||
final processedBytes = await compute(
|
final processedBytes = await compute(_processStreamImage, imageBytes);
|
||||||
_processStreamImage, [imageBytes, _selectedFilter.index]);
|
|
||||||
final file = File(path)..writeAsBytesSync(processedBytes);
|
final file = File(path)..writeAsBytesSync(processedBytes);
|
||||||
|
|
||||||
// Detect objects in the image using YOLO
|
// Detect objects in the image using YOLO
|
||||||
@@ -396,232 +379,49 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _showImageSettingsDialog() {
|
void _showImageSettingsDialog() {
|
||||||
showDialog(
|
showImageSettingsSheet(
|
||||||
context: context,
|
context,
|
||||||
builder: (BuildContext context) {
|
initial: _image,
|
||||||
return StatefulBuilder(
|
settingsId: widget.settingsId,
|
||||||
builder: (context, setDialogState) {
|
cameraLabel: "${_t('Camera')} ${widget.title}",
|
||||||
return Dialog(
|
accent: _bulletColor,
|
||||||
backgroundColor: Colors.grey[900],
|
t: _t,
|
||||||
shape: RoundedRectangleBorder(
|
onChanged: (value) => setState(() => _image = value),
|
||||||
borderRadius: BorderRadius.circular(16)),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(24.0),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
_t('Image Settings'),
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.close, color: Colors.white),
|
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Text(
|
|
||||||
'${_t('Brightness')}: ${(_brightness * 100).toInt()}',
|
|
||||||
style:
|
|
||||||
const TextStyle(color: Colors.white70, fontSize: 14),
|
|
||||||
),
|
|
||||||
Slider(
|
|
||||||
value: _brightness,
|
|
||||||
min: -1.0,
|
|
||||||
max: 1.0,
|
|
||||||
divisions: 40,
|
|
||||||
activeColor: _bulletColor,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() => _brightness = value);
|
|
||||||
setDialogState(() {});
|
|
||||||
_saveBrightnessContrast();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
'${_t('Contrast')}: ${(_contrast * 100).toInt()}%',
|
|
||||||
style:
|
|
||||||
const TextStyle(color: Colors.white70, fontSize: 14),
|
|
||||||
),
|
|
||||||
Slider(
|
|
||||||
value: _contrast,
|
|
||||||
min: 0.5,
|
|
||||||
max: 2.0,
|
|
||||||
divisions: 30,
|
|
||||||
activeColor: _bulletColor,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() => _contrast = value);
|
|
||||||
setDialogState(() {});
|
|
||||||
_saveBrightnessContrast();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Text(
|
|
||||||
_t('Filter'),
|
|
||||||
style:
|
|
||||||
const TextStyle(color: Colors.white70, fontSize: 14),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Wrap(
|
|
||||||
spacing: 8,
|
|
||||||
runSpacing: 8,
|
|
||||||
children: ImageFilterType.values.map((f) {
|
|
||||||
final isSelected = _selectedFilter == f;
|
|
||||||
final label = f.toString().split('.').last;
|
|
||||||
final translatedLabel =
|
|
||||||
_t(label[0].toUpperCase() + label.substring(1));
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () async {
|
|
||||||
setState(() => _selectedFilter = f);
|
|
||||||
setDialogState(() {});
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
await prefs.setInt('selectedFilter', f.index);
|
|
||||||
},
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 14, vertical: 8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color:
|
|
||||||
isSelected ? _bulletColor : Colors.grey[800],
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
translatedLabel,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white, fontSize: 13),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Align(
|
|
||||||
alignment: Alignment.centerRight,
|
|
||||||
child: TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
_brightness = 0.0;
|
|
||||||
_contrast = 1.0;
|
|
||||||
});
|
|
||||||
setDialogState(() {});
|
|
||||||
_saveBrightnessContrast();
|
|
||||||
},
|
|
||||||
child: Text(_t('Reset'),
|
|
||||||
style: const TextStyle(color: Colors.white54)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showBulletDialog() {
|
void _showBulletDialog() {
|
||||||
showDialog(
|
showCameraSheet(
|
||||||
context: context,
|
context,
|
||||||
builder: (BuildContext context) {
|
builder: (sheet) => StatefulBuilder(
|
||||||
return StatefulBuilder(
|
builder: (context, setSheetState) {
|
||||||
builder: (context, setDialogState) {
|
|
||||||
Future<void> setCount(int count) async {
|
Future<void> setCount(int count) async {
|
||||||
final clamped = count.clamp(1, 10);
|
final clamped = count.clamp(1, 10);
|
||||||
setState(() => _numberOfBullets = clamped);
|
setState(() => _numberOfBullets = clamped);
|
||||||
setDialogState(() {});
|
setSheetState(() {});
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
await prefs.setInt('bulletCount', clamped);
|
await prefs.setInt('bulletCount', clamped);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Dialog(
|
return Column(
|
||||||
backgroundColor: Colors.grey[900],
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(16)),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(24.0),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
CameraSheetHeader(
|
||||||
_t('Select the number of bullets'),
|
title: _t('Select the number of bullets'),
|
||||||
textAlign: TextAlign.center,
|
subtitle: '1 – 10',
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.bold),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
SheetStepper(
|
||||||
Row(
|
value: _numberOfBullets,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
min: 1,
|
||||||
children: [
|
max: 10,
|
||||||
IconButton(
|
accent: _bulletColor,
|
||||||
onPressed: _numberOfBullets > 1
|
onChanged: setCount,
|
||||||
? () => setCount(_numberOfBullets - 1)
|
|
||||||
: null,
|
|
||||||
icon: const Icon(Icons.remove,
|
|
||||||
color: Colors.white, size: 28),
|
|
||||||
style: IconButton.styleFrom(
|
|
||||||
backgroundColor: _numberOfBullets > 1
|
|
||||||
? Colors.grey[700]
|
|
||||||
: Colors.grey[850],
|
|
||||||
shape: const CircleBorder(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 24),
|
|
||||||
Text(
|
|
||||||
'$_numberOfBullets',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 48,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: _bulletColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 24),
|
|
||||||
IconButton(
|
|
||||||
onPressed: _numberOfBullets < 10
|
|
||||||
? () => setCount(_numberOfBullets + 1)
|
|
||||||
: null,
|
|
||||||
icon: const Icon(Icons.add,
|
|
||||||
color: Colors.white, size: 28),
|
|
||||||
style: IconButton.styleFrom(
|
|
||||||
backgroundColor: _numberOfBullets < 10
|
|
||||||
? Colors.grey[700]
|
|
||||||
: Colors.grey[850],
|
|
||||||
shape: const CircleBorder(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
|
||||||
'1 – 10',
|
|
||||||
style:
|
|
||||||
const TextStyle(color: Colors.white38, fontSize: 12),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: _bulletColor,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
),
|
|
||||||
child: Text(_t('Done')),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -706,6 +506,7 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
_flashController.dispose();
|
_flashController.dispose();
|
||||||
_zoomAnimController.dispose();
|
_zoomAnimController.dispose();
|
||||||
_yoloDetector.close();
|
_yoloDetector.close();
|
||||||
|
WifiBinding.release();
|
||||||
_restoreScreenSettings();
|
_restoreScreenSettings();
|
||||||
_setSystemBarStyle();
|
_setSystemBarStyle();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
@@ -1470,8 +1271,8 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _showTimerDialog() {
|
void _showTimerDialog() {
|
||||||
showDialog(
|
showCameraSheet(
|
||||||
context: context,
|
context,
|
||||||
builder: (ctx) => _TimerConfigDialog(
|
builder: (ctx) => _TimerConfigDialog(
|
||||||
shootSeconds: _shootSeconds,
|
shootSeconds: _shootSeconds,
|
||||||
reloadSeconds: _reloadSecondsRaw,
|
reloadSeconds: _reloadSecondsRaw,
|
||||||
@@ -1510,142 +1311,11 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorFilter _buildColorFilter() {
|
|
||||||
// Base filter matrix
|
|
||||||
List<double> baseMatrix;
|
|
||||||
|
|
||||||
switch (_selectedFilter) {
|
|
||||||
case ImageFilterType.greyscale:
|
|
||||||
baseMatrix = [
|
|
||||||
0.2126,
|
|
||||||
0.7152,
|
|
||||||
0.0722,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0.2126,
|
|
||||||
0.7152,
|
|
||||||
0.0722,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0.2126,
|
|
||||||
0.7152,
|
|
||||||
0.0722,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case ImageFilterType.invert:
|
|
||||||
baseMatrix = [
|
|
||||||
-1.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
255.0,
|
|
||||||
0.0,
|
|
||||||
-1.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
255.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
-1.0,
|
|
||||||
0.0,
|
|
||||||
255.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
1.0,
|
|
||||||
0.0,
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
baseMatrix = [
|
|
||||||
1.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
1.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
1.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
1.0,
|
|
||||||
0.0,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply brightness and contrast adjustments
|
|
||||||
final b = _brightness * 255.0; // Convert to 0-255 range
|
|
||||||
final c = _contrast;
|
|
||||||
|
|
||||||
// Combine filter with brightness/contrast
|
|
||||||
final adjustedMatrix = <double>[
|
|
||||||
c,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
b,
|
|
||||||
0.0,
|
|
||||||
c,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
b,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
c,
|
|
||||||
0.0,
|
|
||||||
b,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
1.0,
|
|
||||||
0.0,
|
|
||||||
];
|
|
||||||
|
|
||||||
// Multiply base matrix with adjustment matrix
|
|
||||||
return ColorFilter.matrix(_multiplyMatrices(baseMatrix, adjustedMatrix));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<double> _multiplyMatrices(List<double> a, List<double> b) {
|
|
||||||
// For simplicity, just apply brightness/contrast on top of base filter
|
|
||||||
final result = <double>[];
|
|
||||||
|
|
||||||
for (int i = 0; i < a.length; i++) {
|
|
||||||
result.add(a[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply contrast to RGB components
|
|
||||||
result[0] = result[0] * b[0]; // R
|
|
||||||
result[6] = result[6] * b[6]; // G
|
|
||||||
result[12] = result[12] * b[12]; // B
|
|
||||||
|
|
||||||
// Apply brightness
|
|
||||||
result[4] = result[4] + b[4]; // R offset
|
|
||||||
result[9] = result[9] + b[9]; // G offset
|
|
||||||
result[14] = result[14] + b[14]; // B offset
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text("${_t('Camera')} ${widget.cameraIndex}"),
|
title: Text("${_t('Camera')} ${widget.title}"),
|
||||||
backgroundColor: Colors.grey[900],
|
backgroundColor: Colors.grey[900],
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
leading: IconButton(
|
leading: IconButton(
|
||||||
@@ -1682,7 +1352,9 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
height: constraints.maxHeight,
|
height: constraints.maxHeight,
|
||||||
child: RepaintBoundary(
|
child: RepaintBoundary(
|
||||||
child: ColorFiltered(
|
child: ColorFiltered(
|
||||||
colorFilter: _buildColorFilter(),
|
colorFilter: _image.colorFilter,
|
||||||
|
child: RotatedBox(
|
||||||
|
quarterTurns: _image.quarterTurns,
|
||||||
child: Mjpeg(
|
child: Mjpeg(
|
||||||
key: ValueKey(_streamUrl),
|
key: ValueKey(_streamUrl),
|
||||||
stream: _streamUrl!,
|
stream: _streamUrl!,
|
||||||
@@ -1707,6 +1379,7 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -1942,12 +1615,13 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
|
|||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.signal_cellular_off,
|
// Mobile data can stay on: the app pins camera traffic to Wi-Fi
|
||||||
|
const Icon(Icons.videocam_outlined,
|
||||||
color: Colors.white, size: 18),
|
color: Colors.white, size: 18),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
_t("Mobile data is disabled"),
|
_t("Cameras and PC are switched on"),
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Colors.white70,
|
color: Colors.white70,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
@@ -2230,40 +1904,15 @@ class _TimerConfigDialogState extends State<_TimerConfigDialog> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final c = widget.bulletColor;
|
final c = widget.bulletColor;
|
||||||
return Dialog(
|
return Column(
|
||||||
backgroundColor: Colors.grey[900],
|
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
padding: const EdgeInsets.all(24.0),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
// Header
|
CameraSheetHeader(
|
||||||
Row(
|
title: _t('Shooting Timer'),
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
icon: Icons.timer,
|
||||||
children: [
|
iconColor: c,
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.timer, color: c, size: 22),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(_t('Shooting Timer'),
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.bold)),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
IconButton(
|
|
||||||
icon:
|
|
||||||
const Icon(Icons.close, color: Colors.white54, size: 20),
|
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
constraints: const BoxConstraints(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
|
|
||||||
// Single / Full target
|
// Single / Full target
|
||||||
Row(
|
Row(
|
||||||
@@ -2385,9 +2034,7 @@ class _TimerConfigDialogState extends State<_TimerConfigDialog> {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.article_outlined,
|
Icon(Icons.article_outlined,
|
||||||
color: _changeTargetEnabled
|
color: _changeTargetEnabled ? Colors.green : Colors.white38,
|
||||||
? Colors.green
|
|
||||||
: Colors.white38,
|
|
||||||
size: 18),
|
size: 18),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Text(_t('Change target sign'),
|
Text(_t('Change target sign'),
|
||||||
@@ -2409,8 +2056,6 @@ class _TimerConfigDialogState extends State<_TimerConfigDialog> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+96
-116
@@ -1,153 +1,133 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import '../services/app_settings.dart';
|
||||||
import 'stream_screen.dart'; // Import the camera stream screen
|
import '../theme/app_theme.dart';
|
||||||
import '../utils/translations.dart';
|
import 'camera_settings_screen.dart';
|
||||||
import '../utils/target_colors.dart';
|
import 'stream_screen.dart';
|
||||||
|
|
||||||
class TargetScreen extends StatefulWidget {
|
/// Shooting: one tile per position. A position with cameras at several
|
||||||
|
/// locations asks where we are shooting before opening the stream.
|
||||||
|
class TargetScreen extends StatelessWidget {
|
||||||
const TargetScreen({super.key});
|
const TargetScreen({super.key});
|
||||||
|
|
||||||
@override
|
void _openPosition(BuildContext context, int position) {
|
||||||
State<TargetScreen> createState() => _TargetScreenState();
|
final s = AppSettings.instance;
|
||||||
}
|
final cameras = s.cameras.camerasAt(position);
|
||||||
|
if (cameras.isEmpty) {
|
||||||
class _TargetScreenState extends State<TargetScreen> {
|
Navigator.push(context, MaterialPageRoute(builder: (_) => const CameraSettingsScreen()));
|
||||||
List<bool> _cameraButtonsEnabled =
|
return;
|
||||||
List.generate(6, (_) => false); // Initially, all buttons are disabled
|
}
|
||||||
String _selectedLanguage = 'English';
|
if (cameras.length == 1) {
|
||||||
late Color _backgroundColor;
|
_openStream(context, position, cameras.keys.first, cameras.values.first);
|
||||||
|
return;
|
||||||
@override
|
}
|
||||||
void initState() {
|
showModalBottomSheet(
|
||||||
super.initState();
|
context: context,
|
||||||
// Initialize with default target background color
|
builder: (sheet) => SafeArea(
|
||||||
_backgroundColor = TargetColors.getBackgroundColor('assets/target.png');
|
child: Column(
|
||||||
_loadLanguage();
|
mainAxisSize: MainAxisSize.min,
|
||||||
_loadSelectedTargetColor();
|
children: [
|
||||||
_loadCameraData();
|
Text(
|
||||||
|
s.t('Where are we shooting?'),
|
||||||
|
style: const TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'${s.t('Camera')} $position',
|
||||||
|
style: const TextStyle(color: Colors.white54, fontSize: 12),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
for (final entry in cameras.entries)
|
||||||
|
ListTile(
|
||||||
|
leading: Icon(Icons.place_rounded, color: s.bulletColor),
|
||||||
|
title: Text(entry.key, style: const TextStyle(color: Colors.white, fontWeight: FontWeight.w600)),
|
||||||
|
subtitle: Text(entry.value, style: const TextStyle(color: Colors.white54)),
|
||||||
|
trailing: entry.key == s.cameras.activeLocation
|
||||||
|
? Icon(Icons.check_rounded, color: s.bulletColor)
|
||||||
|
: const Icon(Icons.chevron_right, color: Colors.white38),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(sheet);
|
||||||
|
_openStream(context, position, entry.key, entry.value);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String _t(String key) {
|
void _openStream(BuildContext context, int position, String location, String ip) {
|
||||||
return AppTranslations.translate(key, _selectedLanguage);
|
AppSettings.instance.setActiveLocation(location);
|
||||||
}
|
Navigator.push(
|
||||||
|
context,
|
||||||
Future<void> _loadLanguage() async {
|
MaterialPageRoute(
|
||||||
final prefs = await SharedPreferences.getInstance();
|
builder: (_) => CameraStreamScreen(cameraIndex: position, ip: ip, location: location),
|
||||||
setState(() {
|
),
|
||||||
_selectedLanguage = prefs.getString('language') ?? 'English';
|
);
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _loadSelectedTargetColor() async {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
final selectedTarget = prefs.getString('selectedTarget') ?? 'assets/target.png';
|
|
||||||
setState(() {
|
|
||||||
_backgroundColor = TargetColors.getBackgroundColor(selectedTarget);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Load the camera IPs from SharedPreferences and update button status
|
|
||||||
Future<void> _loadCameraData() async {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
final List<String> defaultIPs = [
|
|
||||||
'192.168.0.134:9081',
|
|
||||||
'192.168.0.134:9082',
|
|
||||||
'192.168.0.134:9083',
|
|
||||||
'192.168.0.134:9084',
|
|
||||||
'192.168.0.134:9085',
|
|
||||||
'192.168.0.134:9086',
|
|
||||||
];
|
|
||||||
|
|
||||||
List<bool> cameraDataStatus = List.generate(6, (index) {
|
|
||||||
String key = 'cameraIP_${index + 1}';
|
|
||||||
|
|
||||||
if (!prefs.containsKey(key)) {
|
|
||||||
prefs.setString(key, defaultIPs[index]);
|
|
||||||
return true; // Default set
|
|
||||||
}
|
|
||||||
|
|
||||||
String? ip = prefs.getString(key);
|
|
||||||
return ip != null && ip.isNotEmpty && ip != 'Not Set';
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!mounted) return;
|
|
||||||
setState(() {
|
|
||||||
_cameraButtonsEnabled = cameraDataStatus;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return ListenableBuilder(
|
||||||
backgroundColor: _backgroundColor,
|
listenable: AppSettings.instance,
|
||||||
body: Padding(
|
builder: (context, _) {
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 32),
|
final s = AppSettings.instance;
|
||||||
child: Column(
|
final setup = s.cameras;
|
||||||
children: [
|
|
||||||
Expanded(
|
return GridView.builder(
|
||||||
child: Column(
|
padding: const EdgeInsets.fromLTRB(24, 32, 24, 32),
|
||||||
children: [
|
itemCount: setup.positions,
|
||||||
// Camera grid (6 cameras)
|
|
||||||
Expanded(
|
|
||||||
child: GridView.builder(
|
|
||||||
itemCount: 6,
|
|
||||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
crossAxisCount: 2,
|
crossAxisCount: 2,
|
||||||
mainAxisSpacing: 16,
|
mainAxisSpacing: 16,
|
||||||
crossAxisSpacing: 16,
|
crossAxisSpacing: 16,
|
||||||
childAspectRatio: 1,
|
|
||||||
),
|
),
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, i) {
|
||||||
final isEnabled = _cameraButtonsEnabled[index];
|
final position = i + 1;
|
||||||
return GestureDetector(
|
final locations = setup.camerasAt(position).keys.toList();
|
||||||
onTap: isEnabled
|
final enabled = locations.isNotEmpty;
|
||||||
? () {
|
final surf = Surfaces.current;
|
||||||
Navigator.push(
|
|
||||||
context,
|
return Material(
|
||||||
MaterialPageRoute(
|
color: enabled ? Colors.grey[900] : surf.card,
|
||||||
builder: (context) =>
|
|
||||||
CameraStreamScreen(cameraIndex: index + 1),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: isEnabled ? Colors.grey[900] : Colors.grey[300],
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
),
|
child: InkWell(
|
||||||
padding: const EdgeInsets.all(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
onTap: () => _openPosition(context, position),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
Icons.videocam_rounded,
|
enabled ? Icons.videocam_rounded : Icons.videocam_off_rounded,
|
||||||
color: isEnabled ? Colors.white : Colors.grey[500],
|
color: enabled ? Colors.white : surf.textSecondary,
|
||||||
size: 36,
|
size: 36,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Text(
|
Text(
|
||||||
"${_t('Camera')} ${index + 1}",
|
'${s.t('Camera')} $position',
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: isEnabled ? Colors.white : Colors.grey[600],
|
color: enabled ? Colors.white : surf.textSecondary,
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text(
|
||||||
|
enabled ? locations.join(' · ') : s.t('Not set up'),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
maxLines: 2,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: TextStyle(fontSize: 12, color: enabled ? Colors.white60 : surf.textSecondary),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import '../theme/app_theme.dart';
|
||||||
import 'package:flutter/services.dart' show rootBundle;
|
import 'package:flutter/services.dart' show rootBundle;
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:image/image.dart' as img;
|
import 'package:image/image.dart' as img;
|
||||||
@@ -85,9 +86,9 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
|||||||
_backgroundColor = _getBackgroundColorForTarget(selectedTarget);
|
_backgroundColor = _getBackgroundColorForTarget(selectedTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
Color _getBackgroundColorForTarget(String targetPath) {
|
// One source of truth for target colors (utils/target_colors.dart)
|
||||||
return TargetColors.getBackgroundColor(targetPath);
|
Color _getBackgroundColorForTarget(String targetPath) =>
|
||||||
}
|
TargetColors.getBackgroundColor(targetPath);
|
||||||
|
|
||||||
Future<void> _loadBulletColor() async {
|
Future<void> _loadBulletColor() async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
@@ -708,7 +709,7 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
|||||||
Container(
|
Container(
|
||||||
height: 30,
|
height: 30,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.grey[300],
|
color: Surfaces.current.card,
|
||||||
borderRadius: const BorderRadius.only(
|
borderRadius: const BorderRadius.only(
|
||||||
topLeft: Radius.circular(16),
|
topLeft: Radius.circular(16),
|
||||||
topRight: Radius.circular(16),
|
topRight: Radius.circular(16),
|
||||||
@@ -719,10 +720,10 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
|||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
child: Text(
|
child: Text(
|
||||||
'${count}x',
|
'${count}x',
|
||||||
style: const TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: Colors.black87,
|
color: Surfaces.current.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -801,7 +802,7 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
|||||||
Container(
|
Container(
|
||||||
height: 30,
|
height: 30,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.grey[300],
|
color: Surfaces.current.card,
|
||||||
borderRadius: const BorderRadius.only(
|
borderRadius: const BorderRadius.only(
|
||||||
topLeft: Radius.circular(16),
|
topLeft: Radius.circular(16),
|
||||||
topRight: Radius.circular(16),
|
topRight: Radius.circular(16),
|
||||||
@@ -810,10 +811,10 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
|||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: Text(
|
child: Text(
|
||||||
'${index + 1}',
|
'${index + 1}',
|
||||||
style: const TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: Colors.black87,
|
color: Surfaces.current.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -0,0 +1,329 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:isolate';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import '../models/camera_setup.dart';
|
||||||
|
import '../models/contact.dart';
|
||||||
|
import 'club_crypto.dart';
|
||||||
|
import '../utils/target_colors.dart';
|
||||||
|
import '../utils/translations.dart';
|
||||||
|
|
||||||
|
/// Single source of truth for user settings. Loaded once in main(); widgets
|
||||||
|
/// rebuild via ListenableBuilder(listenable: AppSettings.instance, ...).
|
||||||
|
///
|
||||||
|
/// Writes the same SharedPreferences keys the rest of the app already reads,
|
||||||
|
/// so screens can migrate to this class one at a time.
|
||||||
|
class AppSettings extends ChangeNotifier {
|
||||||
|
AppSettings._();
|
||||||
|
static final AppSettings instance = AppSettings._();
|
||||||
|
|
||||||
|
static const String defaultTarget = 'assets/target.png';
|
||||||
|
static const List<int> reminderHourOptions = [1, 2, 3, 6, 12, 24, 48];
|
||||||
|
|
||||||
|
static const List<Map<String, String>> languages = [
|
||||||
|
{'name': 'English', 'flag': '🇬🇧'},
|
||||||
|
{'name': 'Slovenian', 'flag': '🇸🇮'},
|
||||||
|
];
|
||||||
|
|
||||||
|
static const Map<String, Color> bulletColors = {
|
||||||
|
'Blue': Colors.blue,
|
||||||
|
'Green': Colors.green,
|
||||||
|
'Yellow': Colors.yellow,
|
||||||
|
'Purple': Colors.purple,
|
||||||
|
'Cyan': Colors.cyan,
|
||||||
|
'Teal': Colors.teal,
|
||||||
|
'Indigo': Colors.indigo,
|
||||||
|
'Pink': Colors.pink,
|
||||||
|
'Lime': Colors.lime,
|
||||||
|
'Mint': Colors.greenAccent,
|
||||||
|
'Orange': Colors.orange,
|
||||||
|
'Violet': Colors.deepPurpleAccent,
|
||||||
|
'Amber': Colors.amber,
|
||||||
|
'Brown': Colors.brown,
|
||||||
|
'Grey': Colors.grey,
|
||||||
|
};
|
||||||
|
|
||||||
|
static final List<String> targets = [
|
||||||
|
defaultTarget,
|
||||||
|
for (int i = 1; i <= 35; i++)
|
||||||
|
if (i != 13) 'assets/targets/Target$i.jpg', // 13 was removed
|
||||||
|
];
|
||||||
|
|
||||||
|
late SharedPreferences _prefs;
|
||||||
|
|
||||||
|
String _language = 'English';
|
||||||
|
bool _followSystemLanguage = false;
|
||||||
|
String _bulletColorName = 'Blue';
|
||||||
|
String _selectedTarget = defaultTarget;
|
||||||
|
int _reminderHours = 1;
|
||||||
|
bool _notifyDezuranje = true;
|
||||||
|
bool _notifySestanek = true;
|
||||||
|
bool _notifyTekma = true;
|
||||||
|
CameraSetup _cameras = const CameraSetup();
|
||||||
|
List<Contact>? _clubContacts; // null until the club code is entered
|
||||||
|
|
||||||
|
String get language => _language;
|
||||||
|
bool get followSystemLanguage => _followSystemLanguage;
|
||||||
|
|
||||||
|
// Phone language (or Android 13+ per-app language) mapped to our two languages
|
||||||
|
static String get systemLanguage =>
|
||||||
|
WidgetsBinding.instance.platformDispatcher.locale.languageCode == 'sl' ? 'Slovenian' : 'English';
|
||||||
|
String get bulletColorName => _bulletColorName;
|
||||||
|
Color get bulletColor => bulletColors[_bulletColorName] ?? Colors.blue;
|
||||||
|
String get selectedTarget => _selectedTarget;
|
||||||
|
Color get backgroundColor => TargetColors.getBackgroundColor(_selectedTarget);
|
||||||
|
bool get isLightBackground => backgroundColor.computeLuminance() > 0.4;
|
||||||
|
int get reminderHours => _reminderHours;
|
||||||
|
bool get notifyDezuranje => _notifyDezuranje;
|
||||||
|
bool get notifySestanek => _notifySestanek;
|
||||||
|
bool get notifyTekma => _notifyTekma;
|
||||||
|
CameraSetup get cameras => _cameras;
|
||||||
|
|
||||||
|
/// Calendar, reminders and contacts are for club members only.
|
||||||
|
bool get clubUnlocked => _clubContacts != null;
|
||||||
|
List<Contact> get clubContacts => _clubContacts ?? const [];
|
||||||
|
|
||||||
|
String t(String key) => AppTranslations.translate(key, _language);
|
||||||
|
|
||||||
|
String targetName(String path) {
|
||||||
|
if (path == defaultTarget) return t('Default Target');
|
||||||
|
return t(path.replaceAll('assets/targets/', '').replaceAll('.jpg', ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> load() async {
|
||||||
|
_prefs = await SharedPreferences.getInstance();
|
||||||
|
// New installs follow the phone; an explicit earlier choice stays as it is
|
||||||
|
final saved = _prefs.getString('language');
|
||||||
|
_followSystemLanguage = _prefs.getBool('languageFollowsSystem') ?? saved == null;
|
||||||
|
_language = _followSystemLanguage ? systemLanguage : saved!;
|
||||||
|
await _prefs.setString('language', _language); // other screens read this key
|
||||||
|
WidgetsBinding.instance.platformDispatcher.onLocaleChanged = _onSystemLocaleChanged;
|
||||||
|
|
||||||
|
final color = _prefs.getString('bulletColor') ?? 'Blue';
|
||||||
|
_bulletColorName = bulletColors.containsKey(color) ? color : 'Blue';
|
||||||
|
|
||||||
|
_selectedTarget = _prefs.getString('selectedTarget') ?? defaultTarget;
|
||||||
|
if (!targets.contains(_selectedTarget)) {
|
||||||
|
// Target no longer shipped: fall back so screens reading prefs don't load a missing image
|
||||||
|
_selectedTarget = defaultTarget;
|
||||||
|
await _prefs.setString('selectedTarget', defaultTarget);
|
||||||
|
}
|
||||||
|
_reminderHours = _prefs.getInt('notificationHours_single') ?? 1;
|
||||||
|
_notifyDezuranje = _prefs.getBool('notifyDezuranje') ?? true;
|
||||||
|
_notifySestanek = _prefs.getBool('notifySestanek') ?? true;
|
||||||
|
_notifyTekma = _prefs.getBool('notifyTekma') ?? true;
|
||||||
|
|
||||||
|
final clubData = _prefs.getString('clubData');
|
||||||
|
if (clubData != null) {
|
||||||
|
_clubContacts = _parseContacts(clubData);
|
||||||
|
_refreshClubData(); // picks up contact changes shipped in an app update
|
||||||
|
}
|
||||||
|
|
||||||
|
final setup = _prefs.getString('cameraSetup');
|
||||||
|
if (setup != null) {
|
||||||
|
_cameras = CameraSetup.fromJson(jsonDecode(setup) as Map<String, dynamic>);
|
||||||
|
} else {
|
||||||
|
// Before locations existed: the six single IPs become location "Kovinar"
|
||||||
|
final old = {
|
||||||
|
for (int p = 1; p <= CameraSetup.maxPositions; p++)
|
||||||
|
if ((_prefs.getString('cameraIP_$p') ?? '').isNotEmpty) p: {'Kovinar': _prefs.getString('cameraIP_$p')!},
|
||||||
|
};
|
||||||
|
if (old.isNotEmpty) {
|
||||||
|
_cameras = CameraSetup(locations: const ['Kovinar'], ips: old, activeLocation: 'Kovinar');
|
||||||
|
await _saveCameras();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setLanguage(String value) async {
|
||||||
|
_language = value;
|
||||||
|
_followSystemLanguage = false;
|
||||||
|
notifyListeners();
|
||||||
|
await _prefs.setString('language', value);
|
||||||
|
await _prefs.setBool('languageFollowsSystem', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> useSystemLanguage() async {
|
||||||
|
_followSystemLanguage = true;
|
||||||
|
_language = systemLanguage;
|
||||||
|
notifyListeners();
|
||||||
|
await _prefs.setString('language', _language);
|
||||||
|
await _prefs.setBool('languageFollowsSystem', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onSystemLocaleChanged() {
|
||||||
|
if (_followSystemLanguage && systemLanguage != _language) useSystemLanguage();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setBulletColor(String name) async {
|
||||||
|
_bulletColorName = name;
|
||||||
|
notifyListeners();
|
||||||
|
await _prefs.setString('bulletColor', name);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setTarget(String path) async {
|
||||||
|
_selectedTarget = path;
|
||||||
|
notifyListeners();
|
||||||
|
await _prefs.setString('selectedTarget', path);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setReminderHours(int hours) async {
|
||||||
|
_reminderHours = hours;
|
||||||
|
notifyListeners();
|
||||||
|
await _prefs.setInt('notificationHours_single', hours);
|
||||||
|
await _prefs.setStringList('notificationHours', [hours.toString()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setNotifyDezuranje(bool v) => _setNotify('notifyDezuranje', v, () => _notifyDezuranje = v);
|
||||||
|
Future<void> setNotifySestanek(bool v) => _setNotify('notifySestanek', v, () => _notifySestanek = v);
|
||||||
|
Future<void> setNotifyTekma(bool v) => _setNotify('notifyTekma', v, () => _notifyTekma = v);
|
||||||
|
|
||||||
|
Future<void> _setNotify(String key, bool value, VoidCallback apply) async {
|
||||||
|
apply();
|
||||||
|
notifyListeners();
|
||||||
|
await _prefs.setBool(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _setCameras(CameraSetup next) async {
|
||||||
|
_cameras = next;
|
||||||
|
notifyListeners();
|
||||||
|
await _saveCameras();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also fills the old cameraIP_1…6 keys (last chosen location) for screens
|
||||||
|
// that still read them, like the spectator view.
|
||||||
|
Future<void> _saveCameras() async {
|
||||||
|
await _prefs.setString('cameraSetup', jsonEncode(_cameras.toJson()));
|
||||||
|
for (int p = 1; p <= CameraSetup.maxPositions; p++) {
|
||||||
|
final at = p <= _cameras.positions ? _cameras.camerasAt(p) : <String, String>{};
|
||||||
|
final ip = at[_cameras.activeLocation] ?? (at.isEmpty ? '' : at.values.first);
|
||||||
|
await _prefs.setString('cameraIP_$p', ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> addLocation(String name) async {
|
||||||
|
if (name.isEmpty || _cameras.locations.contains(name)) return false;
|
||||||
|
await _setCameras(_cameras.copyWith(locations: [..._cameras.locations, name]));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> renameLocation(String from, String to) async {
|
||||||
|
if (to.isEmpty || (to != from && _cameras.locations.contains(to))) return false;
|
||||||
|
final ips = _cameras.ipsCopy();
|
||||||
|
for (final m in ips.values) {
|
||||||
|
if (m.containsKey(from)) m[to] = m.remove(from)!;
|
||||||
|
}
|
||||||
|
await _setCameras(CameraSetup(
|
||||||
|
locations: [for (final l in _cameras.locations) l == from ? to : l],
|
||||||
|
positions: _cameras.positions,
|
||||||
|
ips: ips,
|
||||||
|
activeLocation: _cameras.activeLocation == from ? to : _cameras.activeLocation,
|
||||||
|
clubLocation: _cameras.clubLocation == from ? to : _cameras.clubLocation,
|
||||||
|
));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> removeLocation(String name) async {
|
||||||
|
final ips = _cameras.ipsCopy();
|
||||||
|
for (final m in ips.values) {
|
||||||
|
m.remove(name);
|
||||||
|
}
|
||||||
|
await _setCameras(CameraSetup(
|
||||||
|
locations: [for (final l in _cameras.locations) if (l != name) l],
|
||||||
|
positions: _cameras.positions,
|
||||||
|
ips: ips,
|
||||||
|
activeLocation: _cameras.activeLocation == name ? null : _cameras.activeLocation,
|
||||||
|
clubLocation: _cameras.clubLocation == name ? null : _cameras.clubLocation,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setPositionCount(int count) =>
|
||||||
|
_setCameras(_cameras.copyWith(positions: count.clamp(1, CameraSetup.maxPositions)));
|
||||||
|
|
||||||
|
Future<void> setCameraIp(int position, String location, String ip) {
|
||||||
|
final ips = _cameras.ipsCopy();
|
||||||
|
(ips[position] ??= {})[location] = ip.trim();
|
||||||
|
return _setCameras(_cameras.copyWith(ips: ips));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Points every position of [location] at one host with consecutive ports (9081, 9082, ...).
|
||||||
|
Future<void> setLocationHost(String location, String host) {
|
||||||
|
final ips = _cameras.ipsCopy();
|
||||||
|
for (int p = 1; p <= _cameras.positions; p++) {
|
||||||
|
(ips[p] ??= {})[location] = '$host:${CameraSetup.firstPort + p - 1}';
|
||||||
|
}
|
||||||
|
return _setCameras(_cameras.copyWith(ips: ips));
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setActiveLocation(String location) => _setCameras(_cameras.copyWith(activeLocation: location));
|
||||||
|
|
||||||
|
// Club data may carry the club's cameras: {"cameras": {"location": "Kovinar", "ips": [...]}}
|
||||||
|
Future<void> _applyClubCameras(String plaintext) async {
|
||||||
|
final data = (jsonDecode(plaintext) as Map<String, dynamic>)['cameras'] as Map<String, dynamic>?;
|
||||||
|
if (data == null) return;
|
||||||
|
final location = data['location'] as String;
|
||||||
|
final clubIps = [for (final ip in data['ips'] as List) ip as String];
|
||||||
|
final ips = _cameras.ipsCopy();
|
||||||
|
for (int i = 0; i < clubIps.length && i < CameraSetup.maxPositions; i++) {
|
||||||
|
(ips[i + 1] ??= {})[location] = clubIps[i];
|
||||||
|
}
|
||||||
|
await _setCameras(_cameras.copyWith(
|
||||||
|
locations: _cameras.locations.contains(location) ? null : [location, ..._cameras.locations],
|
||||||
|
positions: clubIps.length.clamp(_cameras.positions, CameraSetup.maxPositions),
|
||||||
|
ips: ips,
|
||||||
|
activeLocation: _cameras.activeLocation ?? location,
|
||||||
|
clubLocation: location,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Decrypts the bundled club data with [code]. Returns false if the code is wrong.
|
||||||
|
Future<bool> unlockClub(String code) async {
|
||||||
|
final encrypted = await _loadClubAsset();
|
||||||
|
if (encrypted == null) return false; // asset missing: run tool/encrypt_club_data.dart
|
||||||
|
|
||||||
|
// Key derivation is deliberately slow; keep it off the UI thread
|
||||||
|
final plaintext = await Isolate.run(() => ClubCrypto.decrypt(encrypted, code));
|
||||||
|
if (plaintext == null) return false;
|
||||||
|
|
||||||
|
_clubContacts = _parseContacts(plaintext);
|
||||||
|
notifyListeners();
|
||||||
|
await _applyClubCameras(plaintext);
|
||||||
|
await _prefs.setString('clubData', plaintext);
|
||||||
|
await _prefs.setString('clubCode', code);
|
||||||
|
await _prefs.setString('clubDataSource', encrypted);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> lockClub() async {
|
||||||
|
_clubContacts = null;
|
||||||
|
notifyListeners();
|
||||||
|
final clubLocation = _cameras.clubLocation;
|
||||||
|
if (clubLocation != null) await removeLocation(clubLocation);
|
||||||
|
await _prefs.remove('clubData');
|
||||||
|
await _prefs.remove('clubCode');
|
||||||
|
await _prefs.remove('clubDataSource');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// If the bundled club.enc changed since unlocking (new app version), decrypt
|
||||||
|
/// it again with the saved code. A changed club code locks the phone again.
|
||||||
|
Future<void> _refreshClubData() async {
|
||||||
|
final encrypted = await _loadClubAsset();
|
||||||
|
final code = _prefs.getString('clubCode');
|
||||||
|
if (encrypted == null || encrypted == _prefs.getString('clubDataSource')) return;
|
||||||
|
if (code == null || !await unlockClub(code)) await lockClub();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<String?> _loadClubAsset() async {
|
||||||
|
try {
|
||||||
|
return await rootBundle.loadString('assets/club.enc');
|
||||||
|
} catch (_) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<Contact> _parseContacts(String json) {
|
||||||
|
final list = (jsonDecode(json) as Map<String, dynamic>)['contacts'] as List;
|
||||||
|
return list.map((c) => Contact.fromJson(c as Map<String, dynamic>)).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'package:cryptography/cryptography.dart';
|
||||||
|
|
||||||
|
/// Encrypts/decrypts the club data (contacts) with the club code as the key,
|
||||||
|
/// so the data can ship inside the public app but is unreadable without the code.
|
||||||
|
///
|
||||||
|
/// No Flutter imports: also used by tool/encrypt_club_data.dart.
|
||||||
|
/// File format (assets/club.enc): JSON {v, salt, nonce, cipher, mac}, base64 values.
|
||||||
|
class ClubCrypto {
|
||||||
|
static const int _iterations = 100000;
|
||||||
|
static final _aes = AesGcm.with256bits();
|
||||||
|
|
||||||
|
/// Codes are compared ignoring case and surrounding spaces.
|
||||||
|
static String normalize(String code) => code.trim().toLowerCase();
|
||||||
|
|
||||||
|
static Future<SecretKey> _deriveKey(String code, List<int> salt) {
|
||||||
|
return Pbkdf2(macAlgorithm: Hmac.sha256(), iterations: _iterations, bits: 256)
|
||||||
|
.deriveKeyFromPassword(password: normalize(code), nonce: salt);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<String> encrypt(String plaintext, String code) async {
|
||||||
|
final salt = SecretKeyData.random(length: 16).bytes;
|
||||||
|
final key = await _deriveKey(code, salt);
|
||||||
|
final box = await _aes.encrypt(utf8.encode(plaintext), secretKey: key);
|
||||||
|
return jsonEncode({
|
||||||
|
'v': 1,
|
||||||
|
'salt': base64Encode(salt),
|
||||||
|
'nonce': base64Encode(box.nonce),
|
||||||
|
'cipher': base64Encode(box.cipherText),
|
||||||
|
'mac': base64Encode(box.mac.bytes),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the plaintext, or null if the code is wrong.
|
||||||
|
static Future<String?> decrypt(String encrypted, String code) async {
|
||||||
|
final data = jsonDecode(encrypted) as Map<String, dynamic>;
|
||||||
|
final key = await _deriveKey(code, base64Decode(data['salt']));
|
||||||
|
final box = SecretBox(
|
||||||
|
base64Decode(data['cipher']),
|
||||||
|
nonce: base64Decode(data['nonce']),
|
||||||
|
mac: Mac(base64Decode(data['mac'])),
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
return utf8.decode(await _aes.decrypt(box, secretKey: key));
|
||||||
|
} on SecretBoxAuthenticationError {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import 'package:timezone/timezone.dart' as tz;
|
|||||||
import 'package:timezone/data/latest.dart' as tz;
|
import 'package:timezone/data/latest.dart' as tz;
|
||||||
import 'package:flutter_timezone/flutter_timezone.dart';
|
import 'package:flutter_timezone/flutter_timezone.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import '../services/app_settings.dart';
|
||||||
import '../services/google_calendar_service.dart';
|
import '../services/google_calendar_service.dart';
|
||||||
|
|
||||||
class NotificationService {
|
class NotificationService {
|
||||||
@@ -92,6 +93,10 @@ class NotificationService {
|
|||||||
/// Fetches the calendar and reschedules all reminders. Call on app start
|
/// Fetches the calendar and reschedules all reminders. Call on app start
|
||||||
/// and whenever notification settings change.
|
/// and whenever notification settings change.
|
||||||
Future<void> rescheduleFromCalendar() async {
|
Future<void> rescheduleFromCalendar() async {
|
||||||
|
if (!AppSettings.instance.clubUnlocked) {
|
||||||
|
await cancelAll(); // reminders are a club-member feature
|
||||||
|
return;
|
||||||
|
}
|
||||||
final service = GoogleCalendarService();
|
final service = GoogleCalendarService();
|
||||||
try {
|
try {
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
@@ -172,28 +177,6 @@ class NotificationService {
|
|||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> scheduleTestNotification() async {
|
|
||||||
try {
|
|
||||||
await initialize();
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
final isSlovenian = (prefs.getString('language') ?? 'English') == 'Slovenian';
|
|
||||||
await _plugin.show(
|
|
||||||
9999,
|
|
||||||
isSlovenian ? 'Testno obvestilo' : 'Test Notification',
|
|
||||||
isSlovenian ? 'Obvestila delujejo!' : 'Notifications are working!',
|
|
||||||
_notifDetails,
|
|
||||||
);
|
|
||||||
final in10s = DateTime.now().add(const Duration(seconds: 10));
|
|
||||||
await _scheduleNotification(
|
|
||||||
id: 9998,
|
|
||||||
title: isSlovenian ? 'Načrtovano testno obvestilo' : 'Scheduled Test',
|
|
||||||
body: isSlovenian ? 'Načrtovana obvestila delujejo!' : 'Scheduled notifications are working!',
|
|
||||||
scheduledDate: in10s,
|
|
||||||
mode: await _scheduleMode(),
|
|
||||||
);
|
|
||||||
} catch (_) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _scheduleNotification({
|
Future<void> _scheduleNotification({
|
||||||
required int id,
|
required int id,
|
||||||
required String title,
|
required String title,
|
||||||
|
|||||||
@@ -0,0 +1,217 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
|
/// One saved target (a JSON file written by the preview screen).
|
||||||
|
class TargetRecord {
|
||||||
|
final File file;
|
||||||
|
final DateTime shotAt;
|
||||||
|
final int score;
|
||||||
|
final int shots;
|
||||||
|
|
||||||
|
const TargetRecord(
|
||||||
|
{required this.file,
|
||||||
|
required this.shotAt,
|
||||||
|
required this.score,
|
||||||
|
required this.shots});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A folder of targets: one training or tournament.
|
||||||
|
class Session {
|
||||||
|
final String name;
|
||||||
|
final bool isTournament;
|
||||||
|
final DateTime date;
|
||||||
|
final List<TargetRecord> targets; // oldest first
|
||||||
|
|
||||||
|
const Session(
|
||||||
|
{required this.name,
|
||||||
|
required this.isTournament,
|
||||||
|
required this.date,
|
||||||
|
required this.targets});
|
||||||
|
|
||||||
|
int get totalScore => targets.fold(0, (sum, t) => sum + t.score);
|
||||||
|
int get shots => targets.fold(0, (sum, t) => sum + t.shots);
|
||||||
|
double? get averagePerShot => shots == 0 ? null : totalScore / shots;
|
||||||
|
List<File> get files => [for (final t in targets) t.file];
|
||||||
|
|
||||||
|
/// The same session limited to targets with [shots] bullets (null = all).
|
||||||
|
Session onlyShots(int? shots) => shots == null
|
||||||
|
? this
|
||||||
|
: Session(name: name, isTournament: isTournament, date: date, targets: [
|
||||||
|
for (final t in targets)
|
||||||
|
if (t.shots == shots) t,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Aggregates over any set of sessions (trainings or tournaments of one format).
|
||||||
|
class ShooterStats {
|
||||||
|
final int sessions;
|
||||||
|
final int targets;
|
||||||
|
final int shots;
|
||||||
|
final TargetRecord? best;
|
||||||
|
final double? averageTarget;
|
||||||
|
final double? averagePerShot;
|
||||||
|
|
||||||
|
const ShooterStats._({
|
||||||
|
required this.sessions,
|
||||||
|
required this.targets,
|
||||||
|
required this.shots,
|
||||||
|
required this.best,
|
||||||
|
required this.averageTarget,
|
||||||
|
required this.averagePerShot,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory ShooterStats.of(List<Session> sessions) {
|
||||||
|
final all = [for (final s in sessions) ...s.targets];
|
||||||
|
final shots = all.fold(0, (sum, t) => sum + t.shots);
|
||||||
|
final total = all.fold(0, (sum, t) => sum + t.score);
|
||||||
|
final ranked = [...all]..sort((a, b) => b.score.compareTo(a.score));
|
||||||
|
final mean = all.isEmpty ? null : total / all.length;
|
||||||
|
|
||||||
|
return ShooterStats._(
|
||||||
|
sessions: sessions.length,
|
||||||
|
targets: all.length,
|
||||||
|
shots: shots,
|
||||||
|
best: ranked.isEmpty ? null : ranked.first,
|
||||||
|
averageTarget: mean,
|
||||||
|
averagePerShot: shots == 0 ? null : total / shots,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reads and edits the saved targets under <documents>/saved_images/<session>/.
|
||||||
|
class TargetRepository {
|
||||||
|
static Future<Directory> _root() async {
|
||||||
|
final dir = Directory(
|
||||||
|
'${(await getApplicationDocumentsDirectory()).path}/saved_images');
|
||||||
|
if (!await dir.exists()) await dir.create(recursive: true);
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sessions, newest first. With [year], only that year's target files are read.
|
||||||
|
static Future<List<Session>> loadSessions({int? year}) async {
|
||||||
|
final sessions = <Session>[];
|
||||||
|
|
||||||
|
for (final folder in await _folders()) {
|
||||||
|
if (year != null && folder.date.year != year) continue;
|
||||||
|
final targets = <TargetRecord>[];
|
||||||
|
for (final file in folder.targetFiles) {
|
||||||
|
final record = await _readTarget(file);
|
||||||
|
if (record != null) targets.add(record);
|
||||||
|
}
|
||||||
|
targets.sort((a, b) => a.shotAt.compareTo(b.shotAt));
|
||||||
|
sessions.add(Session(
|
||||||
|
name: folder.name,
|
||||||
|
isTournament: folder.isTournament,
|
||||||
|
date: folder.date,
|
||||||
|
targets: targets,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
sessions.sort((a, b) => b.date.compareTo(a.date));
|
||||||
|
return sessions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Years that have at least one session, newest first. Reads only metadata.
|
||||||
|
static Future<List<int>> years() async {
|
||||||
|
final years = {for (final f in await _folders()) f.date.year}.toList();
|
||||||
|
return years..sort((a, b) => b.compareTo(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cheap pass over the folders: metadata + file names, no target files read
|
||||||
|
static Future<List<_FolderInfo>> _folders() async {
|
||||||
|
final root = await _root();
|
||||||
|
final result = <_FolderInfo>[];
|
||||||
|
for (final folder in root.listSync().whereType<Directory>()) {
|
||||||
|
final meta = await _readMetadata(folder);
|
||||||
|
final files = [
|
||||||
|
for (final f in folder.listSync().whereType<File>())
|
||||||
|
if (f.path.endsWith('.json') && !f.path.endsWith('metadata.json')) f,
|
||||||
|
];
|
||||||
|
final fileTimes = files.map(_timeFromFileName).whereType<DateTime>().toList()..sort();
|
||||||
|
result.add(_FolderInfo(
|
||||||
|
name: folder.path.split('/').last,
|
||||||
|
isTournament: meta['isTournament'] == true,
|
||||||
|
date: DateTime.tryParse(meta['createdAt'] ?? '') ??
|
||||||
|
(fileTimes.isNotEmpty ? fileTimes.first : folder.statSync().changed),
|
||||||
|
targetFiles: files,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<Map<String, dynamic>> _readMetadata(Directory folder) async {
|
||||||
|
final file = File('${folder.path}/metadata.json');
|
||||||
|
if (!await file.exists()) return {};
|
||||||
|
try {
|
||||||
|
return jsonDecode(await file.readAsString()) as Map<String, dynamic>;
|
||||||
|
} catch (_) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<TargetRecord?> _readTarget(File file) async {
|
||||||
|
try {
|
||||||
|
final data =
|
||||||
|
jsonDecode(await file.readAsString()) as Map<String, dynamic>;
|
||||||
|
final score = data['totalScore'];
|
||||||
|
return TargetRecord(
|
||||||
|
file: file,
|
||||||
|
shotAt: _timeFromFileName(file) ?? file.statSync().modified,
|
||||||
|
score: score is int ? score : 0,
|
||||||
|
// Older saves have no bulletCount: fall back to the detected bullets
|
||||||
|
shots: data['bulletCount'] as int? ??
|
||||||
|
(data['bullets'] as List?)?.length ??
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
} catch (_) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// File names look like target_2026-10-26_17-5-3.json (see preview_screen _performSave)
|
||||||
|
static DateTime? _timeFromFileName(File file) {
|
||||||
|
final match = RegExp(r'target_(\d+)-(\d+)-(\d+)_(\d+)-(\d+)-(\d+)\.json$')
|
||||||
|
.firstMatch(file.path);
|
||||||
|
if (match == null) return null;
|
||||||
|
final p = [for (int i = 1; i <= 6; i++) int.parse(match.group(i)!)];
|
||||||
|
return DateTime(p[0], p[1], p[2], p[3], p[4], p[5]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Renames a session and/or changes its type. Returns false if the new name is taken.
|
||||||
|
static Future<bool> updateSession(Session session,
|
||||||
|
{required String name, required bool isTournament}) async {
|
||||||
|
final root = await _root();
|
||||||
|
var folder = Directory('${root.path}/${session.name}');
|
||||||
|
if (name != session.name) {
|
||||||
|
final target = Directory('${root.path}/$name');
|
||||||
|
if (await target.exists()) return false;
|
||||||
|
folder = await folder.rename(target.path);
|
||||||
|
}
|
||||||
|
final metaFile = File('${folder.path}/metadata.json');
|
||||||
|
final meta = await _readMetadata(folder);
|
||||||
|
await metaFile.writeAsString(jsonEncode({
|
||||||
|
'isTournament': isTournament,
|
||||||
|
'createdAt': meta['createdAt'] ?? session.date.toIso8601String(),
|
||||||
|
}));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> deleteSession(Session session) async {
|
||||||
|
final folder = Directory('${(await _root()).path}/${session.name}');
|
||||||
|
if (await folder.exists()) await folder.delete(recursive: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> deleteTarget(TargetRecord target) async {
|
||||||
|
if (await target.file.exists()) await target.file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FolderInfo {
|
||||||
|
final String name;
|
||||||
|
final bool isTournament;
|
||||||
|
final DateTime date;
|
||||||
|
final List<File> targetFiles;
|
||||||
|
|
||||||
|
const _FolderInfo({required this.name, required this.isTournament, required this.date, required this.targetFiles});
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
/// Routes the app's traffic over Wi-Fi while camera screens are open, so the
|
||||||
|
/// cameras stay reachable when the range Wi-Fi has no internet and Android
|
||||||
|
/// would otherwise prefer mobile data. Other apps are not affected.
|
||||||
|
class WifiBinding {
|
||||||
|
static const _channel = MethodChannel('si.sdkkovinar.app/network');
|
||||||
|
static int _users = 0;
|
||||||
|
|
||||||
|
/// Call from initState; await before connecting to a camera.
|
||||||
|
static Future<void> acquire() async {
|
||||||
|
_users++;
|
||||||
|
if (_users > 1 || !Platform.isAndroid) return;
|
||||||
|
try {
|
||||||
|
await _channel.invokeMethod('bindToWifi');
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Call from dispose.
|
||||||
|
static Future<void> release() async {
|
||||||
|
if (_users == 0) return;
|
||||||
|
_users--;
|
||||||
|
if (_users > 0 || !Platform.isAndroid) return;
|
||||||
|
try {
|
||||||
|
await _channel.invokeMethod('unbind');
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../services/app_settings.dart';
|
||||||
|
|
||||||
|
/// Shared colors and component styles. Prefer these over hardcoded
|
||||||
|
/// Colors.grey[...] so screens look alike and can be restyled in one place.
|
||||||
|
class AppTheme {
|
||||||
|
static final Color bar = Colors.grey[900]!; // app bar, bottom nav, sheets
|
||||||
|
static final Color sheet = Colors.grey[900]!;
|
||||||
|
|
||||||
|
static ThemeData light() {
|
||||||
|
return ThemeData(
|
||||||
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.white),
|
||||||
|
useMaterial3: true,
|
||||||
|
bottomSheetTheme: BottomSheetThemeData(
|
||||||
|
backgroundColor: sheet,
|
||||||
|
showDragHandle: true,
|
||||||
|
dragHandleColor: Colors.white24,
|
||||||
|
shape: const RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
dialogTheme: DialogThemeData(
|
||||||
|
backgroundColor: sheet,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
|
titleTextStyle: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),
|
||||||
|
contentTextStyle: const TextStyle(color: Colors.white70, fontSize: 14),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ThemeData dark() {
|
||||||
|
return light().copyWith(
|
||||||
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue, brightness: Brightness.dark),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Card and text colors that stay readable on the current target background
|
||||||
|
/// (which can be anything from white to red to black).
|
||||||
|
class Surfaces {
|
||||||
|
final Color card;
|
||||||
|
final Color divider;
|
||||||
|
final Color textPrimary;
|
||||||
|
final Color textSecondary;
|
||||||
|
|
||||||
|
const Surfaces._({
|
||||||
|
required this.card,
|
||||||
|
required this.divider,
|
||||||
|
required this.textPrimary,
|
||||||
|
required this.textSecondary,
|
||||||
|
});
|
||||||
|
|
||||||
|
static Surfaces get current => AppSettings.instance.isLightBackground
|
||||||
|
? Surfaces._(
|
||||||
|
card: Colors.grey[300]!, // same grey as calendar cards
|
||||||
|
divider: Colors.grey[400]!,
|
||||||
|
textPrimary: Colors.black87,
|
||||||
|
textSecondary: Colors.black54,
|
||||||
|
)
|
||||||
|
: Surfaces._(
|
||||||
|
card: Colors.grey[850]!,
|
||||||
|
divider: Colors.grey[700]!,
|
||||||
|
textPrimary: Colors.white,
|
||||||
|
textSecondary: Colors.white60,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -15,7 +15,6 @@ class TargetColors {
|
|||||||
'assets/targets/Target10.jpg': Color(0xFF98926E), // Olive green
|
'assets/targets/Target10.jpg': Color(0xFF98926E), // Olive green
|
||||||
'assets/targets/Target11.jpg': Color(0xFF13132B), // Dark blue
|
'assets/targets/Target11.jpg': Color(0xFF13132B), // Dark blue
|
||||||
'assets/targets/Target12.jpg': Color(0xFFF5F4EF), // Off-white
|
'assets/targets/Target12.jpg': Color(0xFFF5F4EF), // Off-white
|
||||||
'assets/targets/Target13.jpg': Color(0xFF174AA5), // Blue
|
|
||||||
'assets/targets/Target14.jpg': Color(0xFFFEE05E), // Light yellow
|
'assets/targets/Target14.jpg': Color(0xFFFEE05E), // Light yellow
|
||||||
'assets/targets/Target15.jpg': Color(0xFFFFFFFF), // White
|
'assets/targets/Target15.jpg': Color(0xFFFFFFFF), // White
|
||||||
'assets/targets/Target16.jpg': Color(0xFF000000), // Black
|
'assets/targets/Target16.jpg': Color(0xFF000000), // Black
|
||||||
|
|||||||
+355
-53
@@ -48,100 +48,140 @@ class AppTranslations {
|
|||||||
'Slovenian': 'Privzeta tarča',
|
'Slovenian': 'Privzeta tarča',
|
||||||
},
|
},
|
||||||
'Target1': {
|
'Target1': {
|
||||||
'English': 'Target 1',
|
'English': 'Leaf Wreath',
|
||||||
'Slovenian': 'Tarča 1',
|
'Slovenian': 'Lovorov venec',
|
||||||
},
|
},
|
||||||
'Target2': {
|
'Target2': {
|
||||||
'English': 'Target 2',
|
'English': 'Spring Meadow',
|
||||||
'Slovenian': 'Tarča 2',
|
'Slovenian': 'Pomladni travnik',
|
||||||
},
|
},
|
||||||
'Target3': {
|
'Target3': {
|
||||||
'English': 'Target 3',
|
'English': 'Stone',
|
||||||
'Slovenian': 'Tarča 3',
|
'Slovenian': 'Kamen',
|
||||||
},
|
},
|
||||||
'Target4': {
|
'Target4': {
|
||||||
'English': 'Target 4',
|
'English': 'Royal Red',
|
||||||
'Slovenian': 'Tarča 4',
|
'Slovenian': 'Kraljevsko rdeča',
|
||||||
},
|
},
|
||||||
'Target5': {
|
'Target5': {
|
||||||
'English': 'Target 5',
|
'English': 'Flames',
|
||||||
'Slovenian': 'Tarča 5',
|
'Slovenian': 'Plameni',
|
||||||
},
|
},
|
||||||
'Target6': {
|
'Target6': {
|
||||||
'English': 'Target 6',
|
'English': 'Classic Beige',
|
||||||
'Slovenian': 'Tarča 6',
|
'Slovenian': 'Klasična bež',
|
||||||
},
|
},
|
||||||
'Target7': {
|
'Target7': {
|
||||||
'English': 'Target 7',
|
'English': 'Sunny Yellow',
|
||||||
'Slovenian': 'Tarča 7',
|
'Slovenian': 'Sončno rumena',
|
||||||
},
|
},
|
||||||
'Target8': {
|
'Target8': {
|
||||||
'English': 'Target 8',
|
'English': 'Wave',
|
||||||
'Slovenian': 'Tarča 8',
|
'Slovenian': 'Val',
|
||||||
},
|
},
|
||||||
'Target9': {
|
'Target9': {
|
||||||
'English': 'Target 9',
|
'English': 'Frost',
|
||||||
'Slovenian': 'Tarča 9',
|
'Slovenian': 'Ivje',
|
||||||
},
|
},
|
||||||
'Target10': {
|
'Target10': {
|
||||||
'English': 'Target 10',
|
'English': 'Military',
|
||||||
'Slovenian': 'Tarča 10',
|
'Slovenian': 'Vojaška',
|
||||||
},
|
},
|
||||||
'Target11': {
|
'Target11': {
|
||||||
'English': 'Target 11',
|
'English': 'Galaxy',
|
||||||
'Slovenian': 'Tarča 11',
|
'Slovenian': 'Galaksija',
|
||||||
},
|
},
|
||||||
'Target12': {
|
'Target12': {
|
||||||
'English': 'Target 12',
|
'English': 'Olive Branch',
|
||||||
'Slovenian': 'Tarča 12',
|
'Slovenian': 'Oljčna vejica',
|
||||||
},
|
|
||||||
'Target13': {
|
|
||||||
'English': 'Target 13',
|
|
||||||
'Slovenian': 'Tarča 13',
|
|
||||||
},
|
},
|
||||||
'Target14': {
|
'Target14': {
|
||||||
'English': 'Target 14',
|
'English': 'Rainbow',
|
||||||
'Slovenian': 'Tarča 14',
|
'Slovenian': 'Mavrica',
|
||||||
},
|
},
|
||||||
'Target15': {
|
'Target15': {
|
||||||
'English': 'Target 15',
|
'English': 'Tribal',
|
||||||
'Slovenian': 'Tarča 15',
|
'Slovenian': 'Plemenska',
|
||||||
},
|
},
|
||||||
'Target16': {
|
'Target16': {
|
||||||
'English': 'Target 16',
|
'English': 'Inferno',
|
||||||
'Slovenian': 'Tarča 16',
|
'Slovenian': 'Inferno',
|
||||||
},
|
},
|
||||||
'Target17': {
|
'Target17': {
|
||||||
'English': 'Target 17',
|
'English': 'Navy Gold',
|
||||||
'Slovenian': 'Tarča 17',
|
'Slovenian': 'Modro-zlata',
|
||||||
},
|
},
|
||||||
'Target18': {
|
'Target18': {
|
||||||
'English': 'Target 18',
|
'English': 'Ice Crystal',
|
||||||
'Slovenian': 'Tarča 18',
|
'Slovenian': 'Ledeni kristal',
|
||||||
},
|
},
|
||||||
'Target19': {
|
'Target19': {
|
||||||
'English': 'Target 19',
|
'English': 'Orange',
|
||||||
'Slovenian': 'Tarča 19',
|
'Slovenian': 'Oranžna',
|
||||||
},
|
},
|
||||||
'Target20': {
|
'Target20': {
|
||||||
'English': 'Target 20',
|
'English': 'Sky Blue',
|
||||||
'Slovenian': 'Tarča 20',
|
'Slovenian': 'Nebesno modra',
|
||||||
},
|
},
|
||||||
'Target21': {
|
'Target21': {
|
||||||
'English': 'Target 21',
|
'English': 'Christmas Wreath',
|
||||||
'Slovenian': 'Tarča 21',
|
'Slovenian': 'Božični venec',
|
||||||
},
|
},
|
||||||
'Target22': {
|
'Target22': {
|
||||||
'English': 'Target 22',
|
'English': 'Paint Splash',
|
||||||
'Slovenian': 'Tarča 22',
|
'Slovenian': 'Barvni pljusk',
|
||||||
},
|
},
|
||||||
'Target23': {
|
'Target23': {
|
||||||
'English': 'Target 23',
|
'English': 'Monochrome',
|
||||||
'Slovenian': 'Tarča 23',
|
'Slovenian': 'Črno-bela',
|
||||||
},
|
},
|
||||||
'Target24': {
|
'Target24': {
|
||||||
'English': 'Target 24',
|
'English': 'Graphite',
|
||||||
'Slovenian': 'Tarča 24',
|
'Slovenian': 'Grafit',
|
||||||
|
},
|
||||||
|
'Target25': {
|
||||||
|
'English': 'Graffiti',
|
||||||
|
'Slovenian': 'Grafiti',
|
||||||
|
},
|
||||||
|
'Target26': {
|
||||||
|
'English': 'Binary',
|
||||||
|
'Slovenian': 'Binarna',
|
||||||
|
},
|
||||||
|
'Target27': {
|
||||||
|
'English': 'Confetti',
|
||||||
|
'Slovenian': 'Konfeti',
|
||||||
|
},
|
||||||
|
'Target28': {
|
||||||
|
'English': 'Shards',
|
||||||
|
'Slovenian': 'Črepinje',
|
||||||
|
},
|
||||||
|
'Target29': {
|
||||||
|
'English': 'Neon',
|
||||||
|
'Slovenian': 'Neon',
|
||||||
|
},
|
||||||
|
'Target30': {
|
||||||
|
'English': 'Ink Splatter',
|
||||||
|
'Slovenian': 'Packe črnila',
|
||||||
|
},
|
||||||
|
'Target31': {
|
||||||
|
'English': 'Christmas Red',
|
||||||
|
'Slovenian': 'Božično rdeča',
|
||||||
|
},
|
||||||
|
'Target32': {
|
||||||
|
'English': 'Holly',
|
||||||
|
'Slovenian': 'Bodika',
|
||||||
|
},
|
||||||
|
'Target33': {
|
||||||
|
'English': 'Easter',
|
||||||
|
'Slovenian': 'Velikonočna',
|
||||||
|
},
|
||||||
|
'Target34': {
|
||||||
|
'English': 'Easter Bunny',
|
||||||
|
'Slovenian': 'Velikonočni zajček',
|
||||||
|
},
|
||||||
|
'Target35': {
|
||||||
|
'English': 'Hearts',
|
||||||
|
'Slovenian': 'Srčki',
|
||||||
},
|
},
|
||||||
|
|
||||||
// Camera settings
|
// Camera settings
|
||||||
@@ -784,9 +824,9 @@ class AppTranslations {
|
|||||||
'English': 'WiFi is enabled',
|
'English': 'WiFi is enabled',
|
||||||
'Slovenian': 'WiFi je vključen',
|
'Slovenian': 'WiFi je vključen',
|
||||||
},
|
},
|
||||||
'Mobile data is disabled': {
|
'Cameras and PC are switched on': {
|
||||||
'English': 'Mobile data is disabled',
|
'English': 'Cameras and PC are switched on',
|
||||||
'Slovenian': 'Mobilni podatki so onemogočeni',
|
'Slovenian': 'Kamere in računalnik so vklopljeni',
|
||||||
},
|
},
|
||||||
'Reload': {
|
'Reload': {
|
||||||
'English': 'Reload',
|
'English': 'Reload',
|
||||||
@@ -978,6 +1018,268 @@ class AppTranslations {
|
|||||||
'English': 'Competitions',
|
'English': 'Competitions',
|
||||||
'Slovenian': 'Tekme',
|
'Slovenian': 'Tekme',
|
||||||
},
|
},
|
||||||
|
// Settings (v1.2 redesign)
|
||||||
|
'Bullet color': {
|
||||||
|
'English': 'Bullet color',
|
||||||
|
'Slovenian': 'Barva zadetkov',
|
||||||
|
},
|
||||||
|
'Remind me': {
|
||||||
|
'English': 'Remind me',
|
||||||
|
'Slovenian': 'Opomni me',
|
||||||
|
},
|
||||||
|
'{n} h before': {
|
||||||
|
'English': '{n} h before',
|
||||||
|
'Slovenian': '{n} h prej',
|
||||||
|
},
|
||||||
|
'Cameras': {
|
||||||
|
'English': 'Cameras',
|
||||||
|
'Slovenian': 'Kamere',
|
||||||
|
},
|
||||||
|
'{n} cameras': {
|
||||||
|
'English': '{n} cameras',
|
||||||
|
'Slovenian': '{n} kamer',
|
||||||
|
},
|
||||||
|
'Quick setup': {
|
||||||
|
'English': 'Quick setup',
|
||||||
|
'Slovenian': 'Hitra nastavitev',
|
||||||
|
},
|
||||||
|
'Set all cameras from one IP': {
|
||||||
|
'English': 'Set all cameras from one IP',
|
||||||
|
'Slovenian': 'Nastavi vse kamere z enim IP',
|
||||||
|
},
|
||||||
|
'Ports {from}–{to}': {
|
||||||
|
'English': 'Ports {from}–{to}',
|
||||||
|
'Slovenian': 'Vrata {from}–{to}',
|
||||||
|
},
|
||||||
|
// Club access
|
||||||
|
'Club': {
|
||||||
|
'English': 'Club',
|
||||||
|
'Slovenian': 'Klub',
|
||||||
|
},
|
||||||
|
'Club code': {
|
||||||
|
'English': 'Club code',
|
||||||
|
'Slovenian': 'Klubska koda',
|
||||||
|
},
|
||||||
|
'Unlocks calendar and contacts': {
|
||||||
|
'English': 'Unlocks calendar and contacts',
|
||||||
|
'Slovenian': 'Odklene koledar in kontakte',
|
||||||
|
},
|
||||||
|
'Member access': {
|
||||||
|
'English': 'Member access',
|
||||||
|
'Slovenian': 'Članski dostop',
|
||||||
|
},
|
||||||
|
'Calendar and contacts unlocked': {
|
||||||
|
'English': 'Calendar and contacts unlocked',
|
||||||
|
'Slovenian': 'Koledar in kontakti odklenjeni',
|
||||||
|
},
|
||||||
|
'Remove': {
|
||||||
|
'English': 'Remove',
|
||||||
|
'Slovenian': 'Odstrani',
|
||||||
|
},
|
||||||
|
'Remove club access from this phone?': {
|
||||||
|
'English': 'Remove club access from this phone?',
|
||||||
|
'Slovenian': 'Odstranim članski dostop s tega telefona?',
|
||||||
|
},
|
||||||
|
'Club access unlocked': {
|
||||||
|
'English': 'Club access unlocked',
|
||||||
|
'Slovenian': 'Članski dostop odklenjen',
|
||||||
|
},
|
||||||
|
'Wrong club code': {
|
||||||
|
'English': 'Wrong club code',
|
||||||
|
'Slovenian': 'Napačna klubska koda',
|
||||||
|
},
|
||||||
|
'Unlock': {
|
||||||
|
'English': 'Unlock',
|
||||||
|
'Slovenian': 'Odkleni',
|
||||||
|
},
|
||||||
|
'Total': {
|
||||||
|
'English': 'Total',
|
||||||
|
'Slovenian': 'Skupaj',
|
||||||
|
},
|
||||||
|
'No training selected': {
|
||||||
|
'English': 'No training selected',
|
||||||
|
'Slovenian': 'Ni izbranega treninga',
|
||||||
|
},
|
||||||
|
'Save to folder': {
|
||||||
|
'English': 'Save to folder',
|
||||||
|
'Slovenian': 'Shrani v mapo',
|
||||||
|
},
|
||||||
|
'All': {
|
||||||
|
'English': 'All',
|
||||||
|
'Slovenian': 'Vse',
|
||||||
|
},
|
||||||
|
'Statistics': {
|
||||||
|
'English': 'Statistics',
|
||||||
|
'Slovenian': 'Statistika',
|
||||||
|
},
|
||||||
|
'Best target': {
|
||||||
|
'English': 'Best target',
|
||||||
|
'Slovenian': 'Najboljša tarča',
|
||||||
|
},
|
||||||
|
'Average target': {
|
||||||
|
'English': 'Average target',
|
||||||
|
'Slovenian': 'Povprečna tarča',
|
||||||
|
},
|
||||||
|
'Average per shot': {
|
||||||
|
'English': 'Average per shot',
|
||||||
|
'Slovenian': 'Povprečje na strel',
|
||||||
|
},
|
||||||
|
'shots': {
|
||||||
|
'English': 'shots',
|
||||||
|
'Slovenian': 'strelov',
|
||||||
|
},
|
||||||
|
'Sessions': {
|
||||||
|
'English': 'Trainings & tournaments',
|
||||||
|
'Slovenian': 'Treningi in tekme',
|
||||||
|
},
|
||||||
|
'Trainings': {
|
||||||
|
'English': 'Trainings',
|
||||||
|
'Slovenian': 'Treningi',
|
||||||
|
},
|
||||||
|
'Sort by Date': {
|
||||||
|
'English': 'By date',
|
||||||
|
'Slovenian': 'Po datumu',
|
||||||
|
},
|
||||||
|
'Sort by Score': {
|
||||||
|
'English': 'By score',
|
||||||
|
'Slovenian': 'Po rezultatu',
|
||||||
|
},
|
||||||
|
'Tournaments': {
|
||||||
|
'English': 'Tournaments',
|
||||||
|
'Slovenian': 'Tekmovanja',
|
||||||
|
},
|
||||||
|
'last': {
|
||||||
|
'English': 'last',
|
||||||
|
'Slovenian': 'zadnji',
|
||||||
|
},
|
||||||
|
'Progress': {
|
||||||
|
'English': 'Progress',
|
||||||
|
'Slovenian': 'Napredek',
|
||||||
|
},
|
||||||
|
'History': {
|
||||||
|
'English': 'History',
|
||||||
|
'Slovenian': 'Zgodovina',
|
||||||
|
},
|
||||||
|
'Average per shot by session': {
|
||||||
|
'English': 'Average per shot by session',
|
||||||
|
'Slovenian': 'Povprečje na strel po treningih',
|
||||||
|
},
|
||||||
|
'Shoot at least two sessions to see your progress': {
|
||||||
|
'English': 'Shoot at least two sessions to see your progress',
|
||||||
|
'Slovenian': 'Za prikaz napredka potrebuješ vsaj dva treninga',
|
||||||
|
},
|
||||||
|
'Edit': {
|
||||||
|
'English': 'Edit',
|
||||||
|
'Slovenian': 'Uredi',
|
||||||
|
},
|
||||||
|
'Delete': {
|
||||||
|
'English': 'Delete',
|
||||||
|
'Slovenian': 'Izbriši',
|
||||||
|
},
|
||||||
|
'A folder with this name already exists': {
|
||||||
|
'English': 'A folder with this name already exists',
|
||||||
|
'Slovenian': 'Mapa s tem imenom že obstaja',
|
||||||
|
},
|
||||||
|
'last training': {
|
||||||
|
'English': 'vs. last training',
|
||||||
|
'Slovenian': 'zadnji trening',
|
||||||
|
},
|
||||||
|
'shot': {
|
||||||
|
'English': 'shot',
|
||||||
|
'Slovenian': 'strel',
|
||||||
|
},
|
||||||
|
'Best results': {
|
||||||
|
'English': 'Best results',
|
||||||
|
'Slovenian': 'Najboljši rezultati',
|
||||||
|
},
|
||||||
|
'Saved targets and your statistics will appear here': {
|
||||||
|
'English': 'Saved targets and your statistics will appear here',
|
||||||
|
'Slovenian': 'Tukaj se bodo prikazale shranjene tarče in tvoja statistika',
|
||||||
|
},
|
||||||
|
'Year': {
|
||||||
|
'English': 'Year',
|
||||||
|
'Slovenian': 'Leto',
|
||||||
|
},
|
||||||
|
'High contrast': {
|
||||||
|
'English': 'High contrast',
|
||||||
|
'Slovenian': 'Visok kontrast',
|
||||||
|
},
|
||||||
|
'Rotate': {
|
||||||
|
'English': 'Rotate',
|
||||||
|
'Slovenian': 'Zasukaj',
|
||||||
|
},
|
||||||
|
'Saved for this camera': {
|
||||||
|
'English': 'saved for this camera',
|
||||||
|
'Slovenian': 'shranjeno za to kamero',
|
||||||
|
},
|
||||||
|
'Image Settings': {
|
||||||
|
'English': 'Image Settings',
|
||||||
|
'Slovenian': 'Nastavitve slike',
|
||||||
|
},
|
||||||
|
'Where are we shooting?': {
|
||||||
|
'English': 'Where are we shooting?',
|
||||||
|
'Slovenian': 'Kje streljamo?',
|
||||||
|
},
|
||||||
|
'Not set up': {
|
||||||
|
'English': 'Not set up',
|
||||||
|
'Slovenian': 'Ni nastavljeno',
|
||||||
|
},
|
||||||
|
'Locations': {
|
||||||
|
'English': 'Locations',
|
||||||
|
'Slovenian': 'Strelišča',
|
||||||
|
},
|
||||||
|
'Location': {
|
||||||
|
'English': 'Location',
|
||||||
|
'Slovenian': 'Strelišče',
|
||||||
|
},
|
||||||
|
'Add location': {
|
||||||
|
'English': 'Add location',
|
||||||
|
'Slovenian': 'Dodaj strelišče',
|
||||||
|
},
|
||||||
|
'Added with the club code': {
|
||||||
|
'English': 'Added with the club code',
|
||||||
|
'Slovenian': 'Dodano s klubsko kodo',
|
||||||
|
},
|
||||||
|
'Positions': {
|
||||||
|
'English': 'Positions',
|
||||||
|
'Slovenian': 'Pozicije',
|
||||||
|
},
|
||||||
|
'Number of positions': {
|
||||||
|
'English': 'Number of positions',
|
||||||
|
'Slovenian': 'Število pozicij',
|
||||||
|
},
|
||||||
|
'e.g. Home': {
|
||||||
|
'English': 'e.g. Home',
|
||||||
|
'Slovenian': 'npr. Doma',
|
||||||
|
},
|
||||||
|
'This location already exists': {
|
||||||
|
'English': 'This location already exists',
|
||||||
|
'Slovenian': 'To strelišče že obstaja',
|
||||||
|
},
|
||||||
|
'Exposure': {
|
||||||
|
'English': 'Exposure',
|
||||||
|
'Slovenian': 'Osvetlitev',
|
||||||
|
},
|
||||||
|
'Zoom': {
|
||||||
|
'English': 'Zoom',
|
||||||
|
'Slovenian': 'Povečava',
|
||||||
|
},
|
||||||
|
'Flashlight': {
|
||||||
|
'English': 'Flashlight',
|
||||||
|
'Slovenian': 'Svetilka',
|
||||||
|
},
|
||||||
|
'Settings icon: exposure, zoom and flashlight': {
|
||||||
|
'English': 'Settings icon: exposure, zoom and flashlight',
|
||||||
|
'Slovenian': 'Ikona nastavitev: osvetlitev, povečava in svetilka',
|
||||||
|
},
|
||||||
|
'Automatic (phone language)': {
|
||||||
|
'English': 'Automatic (phone language)',
|
||||||
|
'Slovenian': 'Samodejno (jezik telefona)',
|
||||||
|
},
|
||||||
|
'Member access is currently available only for SDK Kovinar Muta. Support for other clubs may be added in the future.': {
|
||||||
|
'English': 'Member access is currently available only for SDK Kovinar Muta. Support for other clubs may be added in the future.',
|
||||||
|
'Slovenian': 'Članski dostop je trenutno na voljo samo za SDK Kovinar Muta. V prihodnje bo morda podprt tudi za druge klube.',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static String translate(String key, String language) {
|
static String translate(String key, String language) {
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../theme/app_theme.dart';
|
||||||
|
|
||||||
|
class BarTab {
|
||||||
|
final String label;
|
||||||
|
final IconData icon;
|
||||||
|
|
||||||
|
const BarTab(this.label, this.icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Tab strip that continues the dark app bar (Koledar/Stiki, Knjiga filters).
|
||||||
|
/// The selected tab is a white pill; [trailing] sits at the right end.
|
||||||
|
class BarTabs extends StatelessWidget {
|
||||||
|
final List<BarTab> tabs;
|
||||||
|
final int selected;
|
||||||
|
final ValueChanged<int> onSelect;
|
||||||
|
final Widget? trailing;
|
||||||
|
|
||||||
|
const BarTabs({
|
||||||
|
super.key,
|
||||||
|
required this.tabs,
|
||||||
|
required this.selected,
|
||||||
|
required this.onSelect,
|
||||||
|
this.trailing,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
color: AppTheme.bar,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
for (int i = 0; i < tabs.length; i++) ...[
|
||||||
|
if (i > 0) const SizedBox(width: 6),
|
||||||
|
Expanded(child: _tab(tabs[i], i == selected, () => onSelect(i))),
|
||||||
|
],
|
||||||
|
if (trailing != null) trailing!,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _tab(BarTab tab, bool active, VoidCallback onTap) {
|
||||||
|
final color = active ? Colors.black : Colors.grey[400];
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: onTap,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: active ? Colors.white : Colors.transparent,
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(tab.icon, color: color, size: 18),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Flexible(
|
||||||
|
child: Text(
|
||||||
|
tab.label,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: color),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
-20
@@ -1,29 +1,30 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../utils/translations.dart';
|
import '../theme/app_theme.dart';
|
||||||
|
|
||||||
class BottomNavBar extends StatelessWidget {
|
class BottomNavBar extends StatelessWidget {
|
||||||
final int selectedIndex;
|
final int selectedIndex;
|
||||||
final Function(int) onItemTapped;
|
final ValueChanged<int> onItemTapped;
|
||||||
final String selectedLanguage;
|
final List<BottomNavigationBarItem> items;
|
||||||
|
|
||||||
const BottomNavBar({
|
const BottomNavBar({
|
||||||
super.key,
|
super.key,
|
||||||
required this.selectedIndex,
|
required this.selectedIndex,
|
||||||
required this.onItemTapped,
|
required this.onItemTapped,
|
||||||
required this.selectedLanguage,
|
required this.items,
|
||||||
});
|
});
|
||||||
|
|
||||||
String _t(String key) {
|
|
||||||
return AppTranslations.translate(key, selectedLanguage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SafeArea(
|
// Paint the gesture-bar strip below the nav too (edge-to-edge since targetSdk 35),
|
||||||
|
// otherwise the target background color shows through as a thin line.
|
||||||
|
return ColoredBox(
|
||||||
|
color: AppTheme.bar,
|
||||||
|
child: SafeArea(
|
||||||
|
top: false,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 80,
|
height: 80,
|
||||||
child: BottomNavigationBar(
|
child: BottomNavigationBar(
|
||||||
backgroundColor: Colors.grey[900],
|
backgroundColor: AppTheme.bar,
|
||||||
currentIndex: selectedIndex,
|
currentIndex: selectedIndex,
|
||||||
onTap: onItemTapped,
|
onTap: onItemTapped,
|
||||||
showSelectedLabels: true,
|
showSelectedLabels: true,
|
||||||
@@ -33,16 +34,10 @@ Widget build(BuildContext context) {
|
|||||||
unselectedFontSize: 12,
|
unselectedFontSize: 12,
|
||||||
selectedItemColor: Colors.white,
|
selectedItemColor: Colors.white,
|
||||||
unselectedItemColor: Colors.white70,
|
unselectedItemColor: Colors.white70,
|
||||||
items: [
|
items: items,
|
||||||
BottomNavigationBarItem(icon: const Icon(Icons.book), label: _t("Book")),
|
),
|
||||||
BottomNavigationBarItem(icon: const Icon(Icons.my_location), label: _t("Shooting")),
|
|
||||||
BottomNavigationBarItem(icon: const Icon(Icons.camera_alt), label: _t("Camera")),
|
|
||||||
BottomNavigationBarItem(icon: const Icon(Icons.calendar_today), label: _t("Calendar")),
|
|
||||||
BottomNavigationBarItem(icon: const Icon(Icons.settings), label: _t("Settings")),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,236 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// Bottom sheet used by every menu on the camera stream: the live image stays
|
||||||
|
/// visible and undimmed above it, so changes can be judged immediately.
|
||||||
|
Future<T?> showCameraSheet<T>(BuildContext context,
|
||||||
|
{required WidgetBuilder builder}) {
|
||||||
|
return showModalBottomSheet<T>(
|
||||||
|
context: context,
|
||||||
|
barrierColor: Colors.transparent,
|
||||||
|
backgroundColor: Colors.grey[900],
|
||||||
|
isScrollControlled:
|
||||||
|
true, // tall content (timer) may use more than half the screen
|
||||||
|
builder: (sheet) => SafeArea(
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints:
|
||||||
|
BoxConstraints(maxHeight: MediaQuery.sizeOf(sheet).height * 0.75),
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 16),
|
||||||
|
child: builder(sheet),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Title (+ optional subtitle) on the left, optional action on the right.
|
||||||
|
class CameraSheetHeader extends StatelessWidget {
|
||||||
|
final String title;
|
||||||
|
final String? subtitle;
|
||||||
|
final IconData? icon;
|
||||||
|
final Color? iconColor;
|
||||||
|
final Widget? trailing;
|
||||||
|
|
||||||
|
const CameraSheetHeader({
|
||||||
|
super.key,
|
||||||
|
required this.title,
|
||||||
|
this.subtitle,
|
||||||
|
this.icon,
|
||||||
|
this.iconColor,
|
||||||
|
this.trailing,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 14),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
if (icon != null) ...[
|
||||||
|
Icon(icon, color: iconColor ?? Colors.white, size: 22),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
],
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(title,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.bold)),
|
||||||
|
if (subtitle != null)
|
||||||
|
Text(subtitle!,
|
||||||
|
style:
|
||||||
|
const TextStyle(color: Colors.white54, fontSize: 12)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (trailing != null) trailing!,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Icon, label, slider and current value in one row.
|
||||||
|
class SheetSlider extends StatelessWidget {
|
||||||
|
final IconData icon;
|
||||||
|
final String label;
|
||||||
|
final String valueText;
|
||||||
|
final double value;
|
||||||
|
final double min;
|
||||||
|
final double max;
|
||||||
|
final Color accent;
|
||||||
|
final ValueChanged<double> onChanged;
|
||||||
|
|
||||||
|
const SheetSlider({
|
||||||
|
required this.icon,
|
||||||
|
required this.label,
|
||||||
|
required this.valueText,
|
||||||
|
required this.value,
|
||||||
|
required this.min,
|
||||||
|
required this.max,
|
||||||
|
required this.accent,
|
||||||
|
required this.onChanged,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
Icon(icon, color: Colors.white54, size: 20),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
SizedBox(
|
||||||
|
width: 72,
|
||||||
|
child: Text(label,
|
||||||
|
style: const TextStyle(color: Colors.white, fontSize: 13)),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Slider(
|
||||||
|
value: value.clamp(min, max),
|
||||||
|
min: min,
|
||||||
|
max: max,
|
||||||
|
activeColor: accent,
|
||||||
|
inactiveColor: Colors.white24,
|
||||||
|
onChanged: onChanged,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 46,
|
||||||
|
child: Text(
|
||||||
|
valueText,
|
||||||
|
textAlign: TextAlign.right,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white70,
|
||||||
|
fontSize: 13,
|
||||||
|
fontFeatures: [FontFeature.tabularFigures()]),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Wide button that shows an on/off state with the accent color.
|
||||||
|
class SheetToggle extends StatelessWidget {
|
||||||
|
final IconData icon;
|
||||||
|
final String label;
|
||||||
|
final bool active;
|
||||||
|
final Color accent;
|
||||||
|
final VoidCallback onTap;
|
||||||
|
|
||||||
|
const SheetToggle({
|
||||||
|
required this.icon,
|
||||||
|
required this.label,
|
||||||
|
required this.active,
|
||||||
|
required this.accent,
|
||||||
|
required this.onTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Material(
|
||||||
|
color: active
|
||||||
|
? accent.withValues(alpha: 0.18)
|
||||||
|
: Colors.white.withValues(alpha: 0.06),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
side:
|
||||||
|
BorderSide(color: active ? accent : Colors.transparent, width: 1.5),
|
||||||
|
),
|
||||||
|
child: InkWell(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
onTap: onTap,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 10),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(icon, size: 18, color: active ? accent : Colors.white70),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Flexible(
|
||||||
|
child: Text(
|
||||||
|
label,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 13,
|
||||||
|
color: active ? Colors.white : Colors.white70),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Big number with − / + buttons, used for the bullet count.
|
||||||
|
class SheetStepper extends StatelessWidget {
|
||||||
|
final int value;
|
||||||
|
final int min;
|
||||||
|
final int max;
|
||||||
|
final Color accent;
|
||||||
|
final ValueChanged<int> onChanged;
|
||||||
|
|
||||||
|
const SheetStepper({
|
||||||
|
super.key,
|
||||||
|
required this.value,
|
||||||
|
required this.min,
|
||||||
|
required this.max,
|
||||||
|
required this.accent,
|
||||||
|
required this.onChanged,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
Widget button(IconData icon, bool enabled, int next) => IconButton(
|
||||||
|
onPressed: enabled ? () => onChanged(next) : null,
|
||||||
|
icon: Icon(icon, color: Colors.white, size: 28),
|
||||||
|
style: IconButton.styleFrom(
|
||||||
|
backgroundColor:
|
||||||
|
Colors.white.withValues(alpha: enabled ? 0.12 : 0.04),
|
||||||
|
shape: const CircleBorder(),
|
||||||
|
minimumSize: const Size(56, 56),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
button(Icons.remove, value > min, value - 1),
|
||||||
|
SizedBox(
|
||||||
|
width: 120,
|
||||||
|
child: Text(
|
||||||
|
'$value',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 56, fontWeight: FontWeight.bold, color: accent),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
button(Icons.add, value < max, value + 1),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,258 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'camera_sheet.dart';
|
||||||
|
|
||||||
|
enum ImageFilterType { none, greyscale, invert, highContrast }
|
||||||
|
|
||||||
|
/// Live-image adjustments for one camera stream. Saved per camera, because
|
||||||
|
/// lighting differs from lane to lane.
|
||||||
|
class ImageAdjustments {
|
||||||
|
final ImageFilterType filter;
|
||||||
|
final double brightness; // -1 … 1
|
||||||
|
final double contrast; // 0.5 … 2
|
||||||
|
final int quarterTurns; // 0–3, for cameras mounted sideways
|
||||||
|
|
||||||
|
const ImageAdjustments({
|
||||||
|
this.filter = ImageFilterType.none,
|
||||||
|
this.brightness = 0,
|
||||||
|
this.contrast = 1,
|
||||||
|
this.quarterTurns = 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
ImageAdjustments copyWith({
|
||||||
|
ImageFilterType? filter,
|
||||||
|
double? brightness,
|
||||||
|
double? contrast,
|
||||||
|
int? quarterTurns,
|
||||||
|
}) {
|
||||||
|
return ImageAdjustments(
|
||||||
|
filter: filter ?? this.filter,
|
||||||
|
brightness: brightness ?? this.brightness,
|
||||||
|
contrast: contrast ?? this.contrast,
|
||||||
|
quarterTurns: quarterTurns ?? this.quarterTurns,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Keeps rotation, resets the picture itself.
|
||||||
|
ImageAdjustments resetPicture() =>
|
||||||
|
copyWith(filter: ImageFilterType.none, brightness: 0, contrast: 1);
|
||||||
|
|
||||||
|
// Older versions stored one global setting; use it until a camera has its own
|
||||||
|
static Future<ImageAdjustments> load(String camera) async {
|
||||||
|
final p = await SharedPreferences.getInstance();
|
||||||
|
final filter =
|
||||||
|
p.getInt('filter_cam$camera') ?? p.getInt('selectedFilter') ?? 0;
|
||||||
|
return ImageAdjustments(
|
||||||
|
filter: ImageFilterType
|
||||||
|
.values[filter.clamp(0, ImageFilterType.values.length - 1)],
|
||||||
|
brightness: p.getDouble('brightness_cam$camera') ??
|
||||||
|
p.getDouble('brightness') ??
|
||||||
|
0,
|
||||||
|
contrast:
|
||||||
|
p.getDouble('contrast_cam$camera') ?? p.getDouble('contrast') ?? 1,
|
||||||
|
quarterTurns: p.getInt('rotation_cam$camera') ?? 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> save(String camera) async {
|
||||||
|
final p = await SharedPreferences.getInstance();
|
||||||
|
await p.setInt('filter_cam$camera', filter.index);
|
||||||
|
await p.setDouble('brightness_cam$camera', brightness);
|
||||||
|
await p.setDouble('contrast_cam$camera', contrast);
|
||||||
|
await p.setInt('rotation_cam$camera', quarterTurns);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Filter first, then contrast around mid-grey and brightness on top.
|
||||||
|
ColorFilter get colorFilter {
|
||||||
|
const lum = [0.2126, 0.7152, 0.0722];
|
||||||
|
final List<double> base = switch (filter) {
|
||||||
|
ImageFilterType.greyscale || ImageFilterType.highContrast => [
|
||||||
|
...lum, 0, 0, //
|
||||||
|
...lum, 0, 0,
|
||||||
|
...lum, 0, 0,
|
||||||
|
0, 0, 0, 1, 0,
|
||||||
|
],
|
||||||
|
ImageFilterType.invert => [
|
||||||
|
-1, 0, 0, 0, 255, //
|
||||||
|
0, -1, 0, 0, 255,
|
||||||
|
0, 0, -1, 0, 255,
|
||||||
|
0, 0, 0, 1, 0,
|
||||||
|
],
|
||||||
|
ImageFilterType.none => [
|
||||||
|
1, 0, 0, 0, 0, //
|
||||||
|
0, 1, 0, 0, 0,
|
||||||
|
0, 0, 1, 0, 0,
|
||||||
|
0, 0, 0, 1, 0,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
// High contrast makes dark holes stand out on a light target
|
||||||
|
final c = contrast * (filter == ImageFilterType.highContrast ? 2.2 : 1);
|
||||||
|
final m = [...base];
|
||||||
|
for (final row in [0, 5, 10]) {
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
m[row + i] *= c;
|
||||||
|
}
|
||||||
|
m[row + 4] = m[row + 4] * c + 128 * (1 - c) + brightness * 255;
|
||||||
|
}
|
||||||
|
return ColorFilter.matrix(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Bottom sheet that leaves the live image visible, so every change is seen immediately.
|
||||||
|
Future<void> showImageSettingsSheet(
|
||||||
|
BuildContext context, {
|
||||||
|
required ImageAdjustments initial,
|
||||||
|
required String settingsId,
|
||||||
|
required String cameraLabel,
|
||||||
|
required Color accent,
|
||||||
|
required String Function(String) t,
|
||||||
|
required ValueChanged<ImageAdjustments> onChanged,
|
||||||
|
}) {
|
||||||
|
var value = initial;
|
||||||
|
return showCameraSheet(
|
||||||
|
context,
|
||||||
|
builder: (sheet) => StatefulBuilder(
|
||||||
|
builder: (context, setSheetState) {
|
||||||
|
void update(ImageAdjustments next) {
|
||||||
|
setSheetState(() => value = next);
|
||||||
|
onChanged(next);
|
||||||
|
next.save(settingsId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
CameraSheetHeader(
|
||||||
|
title: t('Image Settings'),
|
||||||
|
subtitle: '$cameraLabel · ${t('Saved for this camera')}',
|
||||||
|
trailing: TextButton.icon(
|
||||||
|
style: TextButton.styleFrom(foregroundColor: Colors.white70),
|
||||||
|
icon: const Icon(Icons.restart_alt_rounded, size: 18),
|
||||||
|
label: Text(t('Reset')),
|
||||||
|
onPressed: () => update(value.resetPicture()),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
for (final (f, icon, label) in [
|
||||||
|
(ImageFilterType.none, Icons.image_outlined, 'None'),
|
||||||
|
(
|
||||||
|
ImageFilterType.greyscale,
|
||||||
|
Icons.filter_b_and_w_rounded,
|
||||||
|
'Greyscale'
|
||||||
|
),
|
||||||
|
(
|
||||||
|
ImageFilterType.highContrast,
|
||||||
|
Icons.contrast_rounded,
|
||||||
|
'High contrast'
|
||||||
|
),
|
||||||
|
(
|
||||||
|
ImageFilterType.invert,
|
||||||
|
Icons.invert_colors_rounded,
|
||||||
|
'Invert'
|
||||||
|
),
|
||||||
|
]) ...[
|
||||||
|
if (f != ImageFilterType.none) const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: _FilterTile(
|
||||||
|
icon: icon,
|
||||||
|
label: t(label),
|
||||||
|
selected: value.filter == f,
|
||||||
|
accent: accent,
|
||||||
|
onTap: () => update(value.copyWith(filter: f)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 14),
|
||||||
|
SheetSlider(
|
||||||
|
icon: Icons.brightness_6_rounded,
|
||||||
|
label: t('Brightness'),
|
||||||
|
valueText:
|
||||||
|
'${value.brightness >= 0 ? '+' : ''}${(value.brightness * 100).round()}',
|
||||||
|
value: value.brightness,
|
||||||
|
min: -1,
|
||||||
|
max: 1,
|
||||||
|
accent: accent,
|
||||||
|
onChanged: (v) => update(value.copyWith(brightness: v)),
|
||||||
|
),
|
||||||
|
SheetSlider(
|
||||||
|
icon: Icons.tonality_rounded,
|
||||||
|
label: t('Contrast'),
|
||||||
|
valueText: '${(value.contrast * 100).round()} %',
|
||||||
|
value: value.contrast,
|
||||||
|
min: 0.5,
|
||||||
|
max: 2,
|
||||||
|
accent: accent,
|
||||||
|
onChanged: (v) => update(value.copyWith(contrast: v)),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
SheetToggle(
|
||||||
|
icon: Icons.rotate_90_degrees_cw_rounded,
|
||||||
|
label: '${t('Rotate')} · ${value.quarterTurns * 90}°',
|
||||||
|
active: value.quarterTurns != 0,
|
||||||
|
accent: accent,
|
||||||
|
onTap: () => update(
|
||||||
|
value.copyWith(quarterTurns: (value.quarterTurns + 1) % 4)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FilterTile extends StatelessWidget {
|
||||||
|
final IconData icon;
|
||||||
|
final String label;
|
||||||
|
final bool selected;
|
||||||
|
final Color accent;
|
||||||
|
final VoidCallback onTap;
|
||||||
|
|
||||||
|
const _FilterTile({
|
||||||
|
required this.icon,
|
||||||
|
required this.label,
|
||||||
|
required this.selected,
|
||||||
|
required this.accent,
|
||||||
|
required this.onTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Material(
|
||||||
|
color: selected
|
||||||
|
? accent.withValues(alpha: 0.18)
|
||||||
|
: Colors.white.withValues(alpha: 0.06),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(14),
|
||||||
|
side:
|
||||||
|
BorderSide(color: selected ? accent : Colors.transparent, width: 2),
|
||||||
|
),
|
||||||
|
child: InkWell(
|
||||||
|
borderRadius: BorderRadius.circular(14),
|
||||||
|
onTap: onTap,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 4),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Icon(icon, color: selected ? accent : Colors.white70, size: 26),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text(
|
||||||
|
label,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: selected ? Colors.white : Colors.white70,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class InputField extends StatelessWidget {
|
|
||||||
final String hintText;
|
|
||||||
final IconData icon;
|
|
||||||
final bool obscureText;
|
|
||||||
final TextEditingController controller;
|
|
||||||
|
|
||||||
const InputField({
|
|
||||||
super.key,
|
|
||||||
required this.hintText,
|
|
||||||
required this.icon,
|
|
||||||
this.obscureText = false,
|
|
||||||
required this.controller,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return TextField(
|
|
||||||
controller: controller,
|
|
||||||
obscureText: obscureText,
|
|
||||||
style: const TextStyle(color: Colors.grey), // Text inside input field is gray
|
|
||||||
decoration: InputDecoration(
|
|
||||||
prefixIcon: Icon(icon, color: Colors.grey), // Icons inside input field are gray
|
|
||||||
hintText: hintText,
|
|
||||||
hintStyle: const TextStyle(color: Colors.grey), // Placeholder text is gray
|
|
||||||
filled: true,
|
|
||||||
fillColor: Colors.grey[300], // Light gray background for inputs
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide.none, // No border
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,174 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class ChartPoint {
|
||||||
|
final String label; // shown in the tooltip and under the first/last point
|
||||||
|
final double value;
|
||||||
|
|
||||||
|
const ChartPoint(this.label, this.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Single-series line chart: 2px line, 8px points, three faint gridlines.
|
||||||
|
/// Tap (or drag) to show the nearest point's label and value.
|
||||||
|
class ProgressChart extends StatefulWidget {
|
||||||
|
final List<ChartPoint> points;
|
||||||
|
final Color color;
|
||||||
|
final Color textColor;
|
||||||
|
final Color gridColor;
|
||||||
|
|
||||||
|
const ProgressChart({
|
||||||
|
super.key,
|
||||||
|
required this.points,
|
||||||
|
required this.color,
|
||||||
|
required this.textColor,
|
||||||
|
required this.gridColor,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ProgressChart> createState() => _ProgressChartState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ProgressChartState extends State<ProgressChart> {
|
||||||
|
int? _selected;
|
||||||
|
|
||||||
|
void _select(Offset position, Size size) {
|
||||||
|
final n = widget.points.length;
|
||||||
|
if (n == 0) return;
|
||||||
|
final plotWidth = size.width - _ChartPainter.leftAxis - _ChartPainter.pad * 2;
|
||||||
|
final x = (position.dx - _ChartPainter.leftAxis - _ChartPainter.pad) / plotWidth;
|
||||||
|
setState(() => _selected = (x * (n - 1)).round().clamp(0, n - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
final size = Size(constraints.maxWidth, 170);
|
||||||
|
return GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTapDown: (d) => _select(d.localPosition, size),
|
||||||
|
onHorizontalDragUpdate: (d) => _select(d.localPosition, size),
|
||||||
|
child: CustomPaint(
|
||||||
|
size: size,
|
||||||
|
painter: _ChartPainter(
|
||||||
|
points: widget.points,
|
||||||
|
color: widget.color,
|
||||||
|
textColor: widget.textColor,
|
||||||
|
gridColor: widget.gridColor,
|
||||||
|
selected: _selected,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ChartPainter extends CustomPainter {
|
||||||
|
static const double leftAxis = 32; // room for y labels
|
||||||
|
static const double pad = 10; // keeps end points inside the plot
|
||||||
|
static const double top = 34; // room for the tooltip
|
||||||
|
static const double bottom = 20; // room for x labels
|
||||||
|
|
||||||
|
final List<ChartPoint> points;
|
||||||
|
final Color color;
|
||||||
|
final Color textColor;
|
||||||
|
final Color gridColor;
|
||||||
|
final int? selected;
|
||||||
|
|
||||||
|
_ChartPainter({
|
||||||
|
required this.points,
|
||||||
|
required this.color,
|
||||||
|
required this.textColor,
|
||||||
|
required this.gridColor,
|
||||||
|
required this.selected,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
void paint(Canvas canvas, Size size) {
|
||||||
|
if (points.isEmpty) return;
|
||||||
|
final values = points.map((p) => p.value);
|
||||||
|
var minV = values.reduce((a, b) => a < b ? a : b);
|
||||||
|
var maxV = values.reduce((a, b) => a > b ? a : b);
|
||||||
|
if (maxV - minV < 1) {
|
||||||
|
minV -= 0.5;
|
||||||
|
maxV += 0.5;
|
||||||
|
}
|
||||||
|
final plot = Rect.fromLTRB(leftAxis + pad, top, size.width - pad, size.height - bottom);
|
||||||
|
|
||||||
|
Offset at(int i) => Offset(
|
||||||
|
points.length == 1 ? plot.center.dx : plot.left + plot.width * i / (points.length - 1),
|
||||||
|
plot.bottom - plot.height * (points[i].value - minV) / (maxV - minV),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Gridlines + y labels (min, mid, max)
|
||||||
|
final grid = Paint()
|
||||||
|
..color = gridColor
|
||||||
|
..strokeWidth = 1;
|
||||||
|
for (final f in [0.0, 0.5, 1.0]) {
|
||||||
|
final y = plot.bottom - plot.height * f;
|
||||||
|
canvas.drawLine(Offset(leftAxis, y), Offset(size.width, y), grid);
|
||||||
|
_text(canvas, (minV + (maxV - minV) * f).toStringAsFixed(1), Offset(0, y - 7), 11, textColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// x labels: first and last only
|
||||||
|
_text(canvas, points.first.label, Offset(plot.left - pad, plot.bottom + 5), 11, textColor);
|
||||||
|
if (points.length > 1) {
|
||||||
|
_text(canvas, points.last.label, Offset(plot.right, plot.bottom + 5), 11, textColor, alignRight: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Line
|
||||||
|
final path = Path()..moveTo(at(0).dx, at(0).dy);
|
||||||
|
for (int i = 1; i < points.length; i++) {
|
||||||
|
path.lineTo(at(i).dx, at(i).dy);
|
||||||
|
}
|
||||||
|
canvas.drawPath(
|
||||||
|
path,
|
||||||
|
Paint()
|
||||||
|
..color = color
|
||||||
|
..strokeWidth = 2
|
||||||
|
..style = PaintingStyle.stroke
|
||||||
|
..strokeJoin = StrokeJoin.round,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Points with a surface ring so they read on top of the line
|
||||||
|
for (int i = 0; i < points.length; i++) {
|
||||||
|
final isSel = i == selected;
|
||||||
|
canvas.drawCircle(at(i), isSel ? 7 : 5, Paint()..color = Colors.white);
|
||||||
|
canvas.drawCircle(at(i), isSel ? 5.5 : 4, Paint()..color = color);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tooltip for the selected point
|
||||||
|
if (selected != null) {
|
||||||
|
final p = at(selected!);
|
||||||
|
canvas.drawLine(Offset(p.dx, plot.top), Offset(p.dx, plot.bottom), grid);
|
||||||
|
final label = '${points[selected!].label} ${points[selected!].value.toStringAsFixed(2)}';
|
||||||
|
final tp = _layout(label, 12, Colors.white, bold: true);
|
||||||
|
final w = tp.width + 16;
|
||||||
|
final left = (p.dx - w / 2).clamp(0.0, size.width - w);
|
||||||
|
canvas.drawRRect(
|
||||||
|
RRect.fromRectAndRadius(Rect.fromLTWH(left, 2, w, 24), const Radius.circular(6)),
|
||||||
|
Paint()..color = Colors.grey[900]!,
|
||||||
|
);
|
||||||
|
tp.paint(canvas, Offset(left + 8, 2 + (24 - tp.height) / 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TextPainter _layout(String text, double size, Color color, {bool bold = false}) {
|
||||||
|
return TextPainter(
|
||||||
|
text: TextSpan(
|
||||||
|
text: text,
|
||||||
|
style: TextStyle(fontSize: size, color: color, fontWeight: bold ? FontWeight.w600 : FontWeight.normal),
|
||||||
|
),
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
)..layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _text(Canvas canvas, String text, Offset at, double size, Color color, {bool alignRight = false}) {
|
||||||
|
final tp = _layout(text, size, color);
|
||||||
|
tp.paint(canvas, alignRight ? at.translate(-tp.width, 0) : at);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool shouldRepaint(_ChartPainter old) =>
|
||||||
|
old.points != points || old.selected != selected || old.color != color || old.textColor != textColor;
|
||||||
|
}
|
||||||
@@ -0,0 +1,248 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../theme/app_theme.dart';
|
||||||
|
|
||||||
|
/// Small uppercase label above a group, e.g. "OBVESTILA".
|
||||||
|
class SectionHeader extends StatelessWidget {
|
||||||
|
final String label;
|
||||||
|
|
||||||
|
const SectionHeader(this.label, {super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(4, 20, 4, 8),
|
||||||
|
child: Text(
|
||||||
|
label.toUpperCase(),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
letterSpacing: 1.4,
|
||||||
|
color: Surfaces.current.textSecondary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Rounded group of rows with thin dividers between them.
|
||||||
|
class GroupCard extends StatelessWidget {
|
||||||
|
final List<Widget> children;
|
||||||
|
|
||||||
|
const GroupCard({super.key, required this.children});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final s = Surfaces.current;
|
||||||
|
return ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(14),
|
||||||
|
child: Material(
|
||||||
|
color: s.card,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
for (int i = 0; i < children.length; i++) ...[
|
||||||
|
if (i > 0) Divider(height: 1, thickness: 1, indent: 16, color: s.divider),
|
||||||
|
children[i],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One settings row: title (+ optional subtitle) on the left, current value and
|
||||||
|
/// a chevron on the right. Pass [trailing] to replace value + chevron (e.g. a Switch).
|
||||||
|
class SettingsTile extends StatelessWidget {
|
||||||
|
final String title;
|
||||||
|
final String? subtitle;
|
||||||
|
final Widget? leading;
|
||||||
|
final String? value;
|
||||||
|
final Widget? valueLeading;
|
||||||
|
final Widget? trailing;
|
||||||
|
final VoidCallback? onTap;
|
||||||
|
|
||||||
|
const SettingsTile({
|
||||||
|
super.key,
|
||||||
|
required this.title,
|
||||||
|
this.subtitle,
|
||||||
|
this.leading,
|
||||||
|
this.value,
|
||||||
|
this.valueLeading,
|
||||||
|
this.trailing,
|
||||||
|
this.onTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final s = Surfaces.current;
|
||||||
|
return InkWell(
|
||||||
|
onTap: onTap,
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(minHeight: 52),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
if (leading != null) ...[leading!, const SizedBox(width: 12)],
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(title, style: TextStyle(fontSize: 15, color: s.textPrimary)),
|
||||||
|
if (subtitle != null)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 2),
|
||||||
|
child: Text(subtitle!, style: TextStyle(fontSize: 12, color: s.textSecondary)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (trailing != null)
|
||||||
|
trailing!
|
||||||
|
else ...[
|
||||||
|
if (valueLeading != null) ...[valueLeading!, const SizedBox(width: 8)],
|
||||||
|
if (value != null)
|
||||||
|
ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(maxWidth: 170),
|
||||||
|
child: Text(
|
||||||
|
value!,
|
||||||
|
style: TextStyle(fontSize: 14, color: s.textSecondary),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (onTap != null) Icon(Icons.chevron_right, color: s.textSecondary),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Settings row with a switch on the right; tapping the row toggles it.
|
||||||
|
class SettingsSwitchTile extends StatelessWidget {
|
||||||
|
final String title;
|
||||||
|
final bool value;
|
||||||
|
final ValueChanged<bool> onChanged;
|
||||||
|
final Color activeColor;
|
||||||
|
|
||||||
|
const SettingsSwitchTile({
|
||||||
|
super.key,
|
||||||
|
required this.title,
|
||||||
|
required this.value,
|
||||||
|
required this.onChanged,
|
||||||
|
required this.activeColor,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SettingsTile(
|
||||||
|
title: title,
|
||||||
|
onTap: () => onChanged(!value),
|
||||||
|
trailing: SizedBox(
|
||||||
|
height: 32,
|
||||||
|
child: FittedBox(
|
||||||
|
child: Switch(
|
||||||
|
value: value,
|
||||||
|
onChanged: onChanged,
|
||||||
|
activeTrackColor: activeColor,
|
||||||
|
activeThumbColor: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Row used inside dark bottom-sheet pickers, with a check on the selected one.
|
||||||
|
class SheetOption extends StatelessWidget {
|
||||||
|
final String label;
|
||||||
|
final Widget? leading;
|
||||||
|
final bool selected;
|
||||||
|
final Color selectedColor;
|
||||||
|
final VoidCallback onTap;
|
||||||
|
|
||||||
|
const SheetOption({
|
||||||
|
super.key,
|
||||||
|
required this.label,
|
||||||
|
this.leading,
|
||||||
|
required this.selected,
|
||||||
|
required this.selectedColor,
|
||||||
|
required this.onTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ListTile(
|
||||||
|
onTap: onTap,
|
||||||
|
leading: leading,
|
||||||
|
title: Text(
|
||||||
|
label,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: selected ? FontWeight.bold : FontWeight.normal,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
trailing: selected ? Icon(Icons.check_rounded, color: selectedColor) : null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Headline number with a small label above and an optional caption below.
|
||||||
|
class StatTile extends StatelessWidget {
|
||||||
|
final String label;
|
||||||
|
final String value;
|
||||||
|
final String? caption;
|
||||||
|
|
||||||
|
const StatTile({super.key, required this.label, required this.value, this.caption});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final s = Surfaces.current;
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 12, 12, 12),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(label, style: TextStyle(fontSize: 12, color: s.textSecondary)),
|
||||||
|
const SizedBox(height: 2),
|
||||||
|
Text(value, style: TextStyle(fontSize: 26, fontWeight: FontWeight.bold, color: s.textPrimary)),
|
||||||
|
if (caption != null)
|
||||||
|
Text(caption!, style: TextStyle(fontSize: 11, color: s.textSecondary), maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Grid of [StatTile]s, two per row, on one card.
|
||||||
|
class StatGrid extends StatelessWidget {
|
||||||
|
final List<StatTile> tiles;
|
||||||
|
|
||||||
|
const StatGrid({super.key, required this.tiles});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final s = Surfaces.current;
|
||||||
|
final rows = <Widget>[];
|
||||||
|
for (int i = 0; i < tiles.length; i += 2) {
|
||||||
|
if (i > 0) rows.add(Divider(height: 1, thickness: 1, color: s.divider));
|
||||||
|
rows.add(IntrinsicHeight(
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
Expanded(child: tiles[i]),
|
||||||
|
VerticalDivider(width: 1, thickness: 1, color: s.divider),
|
||||||
|
Expanded(child: i + 1 < tiles.length ? tiles[i + 1] : const SizedBox()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(14),
|
||||||
|
child: ColoredBox(color: s.card, child: Column(children: rows)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../services/app_settings.dart';
|
||||||
|
|
||||||
|
/// Dark dialog with one text field. Returns the trimmed text, or null if cancelled.
|
||||||
|
/// [onReset] adds a secondary button ([resetLabel], default "Reset to Default") that closes the dialog.
|
||||||
|
Future<String?> showTextPrompt(
|
||||||
|
BuildContext context, {
|
||||||
|
required String title,
|
||||||
|
String? message,
|
||||||
|
String initial = '',
|
||||||
|
String? hint,
|
||||||
|
TextInputType keyboardType = TextInputType.text,
|
||||||
|
String? confirmLabel,
|
||||||
|
String? resetLabel,
|
||||||
|
VoidCallback? onReset,
|
||||||
|
}) {
|
||||||
|
final s = AppSettings.instance;
|
||||||
|
final controller = TextEditingController(text: initial);
|
||||||
|
|
||||||
|
return showDialog<String>(
|
||||||
|
context: context,
|
||||||
|
builder: (dialog) => AlertDialog(
|
||||||
|
title: Text(title),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
if (message != null) ...[
|
||||||
|
Text(message),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
],
|
||||||
|
TextField(
|
||||||
|
controller: controller,
|
||||||
|
autofocus: true,
|
||||||
|
keyboardType: keyboardType,
|
||||||
|
autocorrect: false,
|
||||||
|
style: const TextStyle(color: Colors.white),
|
||||||
|
cursorColor: s.bulletColor,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: hint,
|
||||||
|
hintStyle: const TextStyle(color: Colors.white38),
|
||||||
|
filled: true,
|
||||||
|
fillColor: Colors.white10,
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide.none,
|
||||||
|
),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: s.bulletColor),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onSubmitted: (v) => Navigator.pop(dialog, v.trim()),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
if (onReset != null)
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
onReset();
|
||||||
|
Navigator.pop(dialog);
|
||||||
|
},
|
||||||
|
child: Text(resetLabel ?? s.t('Reset to Default'), style: const TextStyle(color: Colors.white54)),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(dialog),
|
||||||
|
child: Text(s.t('Cancel'), style: const TextStyle(color: Colors.white70)),
|
||||||
|
),
|
||||||
|
FilledButton(
|
||||||
|
style: FilledButton.styleFrom(backgroundColor: s.bulletColor),
|
||||||
|
onPressed: () => Navigator.pop(dialog, controller.text.trim()),
|
||||||
|
child: Text(confirmLabel ?? s.t('Save')),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
+9
-73
@@ -1,14 +1,6 @@
|
|||||||
# Generated by pub
|
# Generated by pub
|
||||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||||
packages:
|
packages:
|
||||||
_discoveryapis_commons:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: _discoveryapis_commons
|
|
||||||
sha256: "113c4100b90a5b70a983541782431b82168b3cae166ab130649c36eb3559d498"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.0.7"
|
|
||||||
archive:
|
archive:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -137,6 +129,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.6"
|
version: "3.0.6"
|
||||||
|
cryptography:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: cryptography
|
||||||
|
sha256: "3eda3029d34ec9095a27a198ac9785630fe525c0eb6a49f3d575272f8e792ef0"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.9.0"
|
||||||
cupertino_icons:
|
cupertino_icons:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -312,70 +312,6 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
google_identity_services_web:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: google_identity_services_web
|
|
||||||
sha256: "55580f436822d64c8ff9a77e37d61f5fb1e6c7ec9d632a43ee324e2a05c3c6c9"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "0.3.3"
|
|
||||||
google_sign_in:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: google_sign_in
|
|
||||||
sha256: d0a2c3bcb06e607bb11e4daca48bd4b6120f0bbc4015ccebbe757d24ea60ed2a
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "6.3.0"
|
|
||||||
google_sign_in_android:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: google_sign_in_android
|
|
||||||
sha256: "4e52c64366bdb3fe758f683b088ee514cc7a95e69c52b5ee9fc5919e1683d21b"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "6.2.0"
|
|
||||||
google_sign_in_ios:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: google_sign_in_ios
|
|
||||||
sha256: "29cd125f58f50ceb40e8253d3c0209e321eee3e5df16cd6d262495f7cad6a2bd"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "5.8.1"
|
|
||||||
google_sign_in_platform_interface:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: google_sign_in_platform_interface
|
|
||||||
sha256: "5f6f79cf139c197261adb6ac024577518ae48fdff8e53205c5373b5f6430a8aa"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.5.0"
|
|
||||||
google_sign_in_web:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: google_sign_in_web
|
|
||||||
sha256: "460547beb4962b7623ac0fb8122d6b8268c951cf0b646dd150d60498430e4ded"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "0.12.4+4"
|
|
||||||
googleapis:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: googleapis
|
|
||||||
sha256: "864f222aed3f2ff00b816c675edf00a39e2aaf373d728d8abec30b37bee1a81c"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "13.2.0"
|
|
||||||
googleapis_auth:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: googleapis_auth
|
|
||||||
sha256: befd71383a955535060acde8792e7efc11d2fccd03dd1d3ec434e85b68775938
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.6.0"
|
|
||||||
http:
|
http:
|
||||||
dependency: "direct overridden"
|
dependency: "direct overridden"
|
||||||
description:
|
description:
|
||||||
@@ -545,7 +481,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.0"
|
version: "2.0.0"
|
||||||
package_info_plus:
|
package_info_plus:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: package_info_plus
|
name: package_info_plus
|
||||||
sha256: "7976bfe4c583170d6cdc7077e3237560b364149fcd268b5f53d95a991963b191"
|
sha256: "7976bfe4c583170d6cdc7077e3237560b364149fcd268b5f53d95a991963b191"
|
||||||
|
|||||||
+4
-4
@@ -2,7 +2,7 @@ name: test1
|
|||||||
description: A new Flutter project.
|
description: A new Flutter project.
|
||||||
publish_to: 'none' # This prevents publishing to pub.dev
|
publish_to: 'none' # This prevents publishing to pub.dev
|
||||||
|
|
||||||
version: 1.1.0+4
|
version: 1.2.0+5
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.3.0 <4.0.0'
|
sdk: '>=3.3.0 <4.0.0'
|
||||||
@@ -11,9 +11,6 @@ dependencies:
|
|||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
cupertino_icons: ^1.0.8
|
cupertino_icons: ^1.0.8
|
||||||
google_sign_in: ^6.1.5
|
|
||||||
googleapis: ^13.2.0
|
|
||||||
googleapis_auth: ^1.6.0
|
|
||||||
shared_preferences: ^2.2.2
|
shared_preferences: ^2.2.2
|
||||||
photo_view: ^0.15.0
|
photo_view: ^0.15.0
|
||||||
screenshot: ^3.0.0
|
screenshot: ^3.0.0
|
||||||
@@ -38,6 +35,8 @@ dependencies:
|
|||||||
flutter_local_notifications: ^18.0.1
|
flutter_local_notifications: ^18.0.1
|
||||||
timezone: ^0.9.4
|
timezone: ^0.9.4
|
||||||
flutter_timezone: ^3.0.0
|
flutter_timezone: ^3.0.0
|
||||||
|
package_info_plus: ^8.3.0
|
||||||
|
cryptography: ^2.9.0
|
||||||
|
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
http: ^0.13.6
|
http: ^0.13.6
|
||||||
@@ -57,6 +56,7 @@ flutter_icons:
|
|||||||
flutter:
|
flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
assets:
|
assets:
|
||||||
|
- assets/club.enc
|
||||||
- assets/logo.png
|
- assets/logo.png
|
||||||
- assets/logo.svg
|
- assets/logo.svg
|
||||||
- assets/target.png
|
- assets/target.png
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
// Encrypts tool/club_data.json into assets/club.enc using the club code.
|
||||||
|
//
|
||||||
|
// dart run tool/encrypt_club_data.dart
|
||||||
|
//
|
||||||
|
// The code is asked interactively (not echoed, not saved in shell history).
|
||||||
|
// tool/club_data.json holds the plain contacts and is gitignored — keep it private.
|
||||||
|
// Re-run after editing contacts or to change the club code, then rebuild the app.
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:test1/services/club_crypto.dart';
|
||||||
|
|
||||||
|
const _input = 'tool/club_data.json';
|
||||||
|
const _output = 'assets/club.enc';
|
||||||
|
|
||||||
|
Future<void> main() async {
|
||||||
|
final source = File(_input);
|
||||||
|
if (!source.existsSync()) {
|
||||||
|
stderr.writeln('Missing $_input');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
final plaintext = source.readAsStringSync();
|
||||||
|
final contacts = (jsonDecode(plaintext) as Map<String, dynamic>)['contacts'] as List;
|
||||||
|
|
||||||
|
final code = _ask('Club code: ');
|
||||||
|
if (ClubCrypto.normalize(code).length < 8) {
|
||||||
|
stderr.writeln('Use at least 8 characters — short codes can be guessed by brute force.');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (_ask('Repeat club code: ') != code) {
|
||||||
|
stderr.writeln('Codes do not match.');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
final encrypted = await ClubCrypto.encrypt(plaintext, code);
|
||||||
|
if (await ClubCrypto.decrypt(encrypted, code) != plaintext) {
|
||||||
|
stderr.writeln('Self-check failed, nothing written.');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
File(_output).writeAsStringSync(encrypted);
|
||||||
|
stdout.writeln('Wrote $_output with ${contacts.length} contacts.');
|
||||||
|
}
|
||||||
|
|
||||||
|
String _ask(String prompt) {
|
||||||
|
stdout.write(prompt);
|
||||||
|
final terminal = stdin.hasTerminal;
|
||||||
|
if (terminal) stdin.echoMode = false;
|
||||||
|
final value = stdin.readLineSync() ?? '';
|
||||||
|
if (terminal) stdin.echoMode = true;
|
||||||
|
stdout.writeln();
|
||||||
|
return value;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user