google preperation 1

This commit is contained in:
2026-10-26 20:48:16 +01:00
parent 9a65ff7ad4
commit 3b50cb0fe9
47 changed files with 4969 additions and 4580 deletions
+120 -140
View File
@@ -1,153 +1,133 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'stream_screen.dart'; // Import the camera stream screen
import '../utils/translations.dart';
import '../utils/target_colors.dart';
import '../services/app_settings.dart';
import '../theme/app_theme.dart';
import 'camera_settings_screen.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});
@override
State<TargetScreen> createState() => _TargetScreenState();
}
class _TargetScreenState extends State<TargetScreen> {
List<bool> _cameraButtonsEnabled =
List.generate(6, (_) => false); // Initially, all buttons are disabled
String _selectedLanguage = 'English';
late Color _backgroundColor;
@override
void initState() {
super.initState();
// Initialize with default target background color
_backgroundColor = TargetColors.getBackgroundColor('assets/target.png');
_loadLanguage();
_loadSelectedTargetColor();
_loadCameraData();
}
String _t(String key) {
return AppTranslations.translate(key, _selectedLanguage);
}
Future<void> _loadLanguage() async {
final prefs = await SharedPreferences.getInstance();
setState(() {
_selectedLanguage = prefs.getString('language') ?? 'English';
});
}
Future<void> _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
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: _backgroundColor,
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 32),
void _openPosition(BuildContext context, int position) {
final s = AppSettings.instance;
final cameras = s.cameras.camerasAt(position);
if (cameras.isEmpty) {
Navigator.push(context, MaterialPageRoute(builder: (_) => const CameraSettingsScreen()));
return;
}
if (cameras.length == 1) {
_openStream(context, position, cameras.keys.first, cameras.values.first);
return;
}
showModalBottomSheet(
context: context,
builder: (sheet) => SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Column(
children: [
// Camera grid (6 cameras)
Expanded(
child: GridView.builder(
itemCount: 6,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 16,
crossAxisSpacing: 16,
childAspectRatio: 1,
),
itemBuilder: (context, index) {
final isEnabled = _cameraButtonsEnabled[index];
return GestureDetector(
onTap: isEnabled
? () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
CameraStreamScreen(cameraIndex: index + 1),
),
);
}
: null,
child: Container(
decoration: BoxDecoration(
color: isEnabled ? Colors.grey[900] : Colors.grey[300],
borderRadius: BorderRadius.circular(16),
),
padding: const EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.videocam_rounded,
color: isEnabled ? Colors.white : Colors.grey[500],
size: 36,
),
const SizedBox(height: 12),
Text(
"${_t('Camera')} ${index + 1}",
textAlign: TextAlign.center,
style: TextStyle(
color: isEnabled ? Colors.white : Colors.grey[600],
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
],
),
),
);
},
),
),
],
),
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),
],
),
),
);
}
void _openStream(BuildContext context, int position, String location, String ip) {
AppSettings.instance.setActiveLocation(location);
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => CameraStreamScreen(cameraIndex: position, ip: ip, location: location),
),
);
}
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: AppSettings.instance,
builder: (context, _) {
final s = AppSettings.instance;
final setup = s.cameras;
return GridView.builder(
padding: const EdgeInsets.fromLTRB(24, 32, 24, 32),
itemCount: setup.positions,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 16,
crossAxisSpacing: 16,
),
itemBuilder: (context, i) {
final position = i + 1;
final locations = setup.camerasAt(position).keys.toList();
final enabled = locations.isNotEmpty;
final surf = Surfaces.current;
return Material(
color: enabled ? Colors.grey[900] : surf.card,
borderRadius: BorderRadius.circular(16),
child: InkWell(
borderRadius: BorderRadius.circular(16),
onTap: () => _openPosition(context, position),
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
enabled ? Icons.videocam_rounded : Icons.videocam_off_rounded,
color: enabled ? Colors.white : surf.textSecondary,
size: 36,
),
const SizedBox(height: 12),
Text(
'${s.t('Camera')} $position',
style: TextStyle(
color: enabled ? Colors.white : surf.textSecondary,
fontSize: 20,
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),
),
],
),
),
),
);
},
);
},
);
}
}