This commit is contained in:
2025-10-16 17:42:46 +02:00
parent dc86955721
commit 2e3a69a23e
12 changed files with 1421 additions and 604 deletions
+38 -20
View File
@@ -9,6 +9,7 @@ import 'package:image/image.dart' as img;
import 'yolo_detector.dart';
import 'preview_screen.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
import '../utils/translations.dart';
enum ImageFilterType { none, greyscale, invert}
@@ -38,10 +39,16 @@ class _CameraStreamScreenState extends State<CameraStreamScreen> with SingleTick
Matrix4? _originalMatrix;
Color _bulletColor = Colors.blue; // default/fallback bullet color
String _selectedLanguage = 'English';
String _t(String key) {
return AppTranslations.translate(key, _selectedLanguage);
}
@override
void initState() {
super.initState();
_loadLanguage();
_loadStreamUrl();
_loadBulletCount();
_loadSelectedFilter();
@@ -61,6 +68,13 @@ class _CameraStreamScreenState extends State<CameraStreamScreen> with SingleTick
);
}
Future<void> _loadLanguage() async {
final prefs = await SharedPreferences.getInstance();
setState(() {
_selectedLanguage = prefs.getString('language') ?? 'English';
});
}
Future<void> _loadBulletColor() async {
final prefs = await SharedPreferences.getInstance();
final selected = prefs.getString('bulletColor') ?? 'Blue';
@@ -297,13 +311,14 @@ Color _getColorFromName(String colorName) {
padding: const EdgeInsets.all(24.0), // Increased padding for better spacing
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.only(bottom: 16.0),
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: Text(
'Select the number of bullets',
style: TextStyle(
_t('Select the number of bullets'),
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
@@ -365,9 +380,9 @@ Color _getColorFromName(String colorName) {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'Choose a Filter',
style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),
Text(
_t('Choose a Filter'),
style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),
),
const SizedBox(height: 16),
Wrap(
@@ -377,6 +392,7 @@ Color _getColorFromName(String colorName) {
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 ElevatedButton(
onPressed: () async {
setState(() {
@@ -384,13 +400,15 @@ Color _getColorFromName(String colorName) {
});
final prefs = await SharedPreferences.getInstance();
await prefs.setInt('selectedFilter', f.index); // Save filter index
Navigator.of(context).pop();
if (context.mounted) {
Navigator.of(context).pop();
}
},
style: ElevatedButton.styleFrom(
backgroundColor: isSelected ? _bulletColor : Colors.grey[800],
foregroundColor: Colors.white,
),
child: Text(label[0].toUpperCase() + label.substring(1)),
child: Text(translatedLabel),
);
}).toList(),
),
@@ -455,7 +473,7 @@ void dispose() {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Target ${widget.cameraIndex}"),
title: Text("${_t('Camera')} ${widget.cameraIndex}"),
backgroundColor: Colors.grey[900],
foregroundColor: Colors.white,
leading: IconButton(
@@ -523,14 +541,14 @@ void dispose() {
Positioned.fill(
child: Container(
color: Colors.black.withOpacity(0.4),
child: const Column(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(color: Colors.white),
SizedBox(height: 16),
const CircularProgressIndicator(color: Colors.white),
const SizedBox(height: 16),
Text(
"Processing image...",
style: TextStyle(color: Colors.white, fontSize: 16),
_t("Processing image..."),
style: const TextStyle(color: Colors.white, fontSize: 16),
),
],
),
@@ -571,14 +589,14 @@ void dispose() {
children: [
const Icon(Icons.error, color: Colors.red, size: 100),
const SizedBox(height: 20),
const Text(
"Unable to load camera stream",
style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
Text(
_t("Unable to load camera stream"),
style: const TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: _loadStreamUrl,
child: const Text("Retry"),
child: Text(_t("Retry")),
),
],
);