bugfix for wrong deletions and calculating average. Cleanup for small diagram changes.

This commit is contained in:
Jan Pleterski
2026-11-13 09:14:50 +01:00
parent df85d36c75
commit d3927aac8a
9 changed files with 0 additions and 939 deletions
-137
View File
@@ -1,137 +0,0 @@
import 'package:flutter/material.dart';
import '../utils/translations.dart';
class CameraSelectionDialog extends StatefulWidget {
final List<Map<String, dynamic>> availableCameras;
final String selectedLanguage;
const CameraSelectionDialog({
super.key,
required this.availableCameras,
required this.selectedLanguage,
});
@override
State<CameraSelectionDialog> createState() => _CameraSelectionDialogState();
}
class _CameraSelectionDialogState extends State<CameraSelectionDialog> {
late List<bool> _selectedCameras;
@override
void initState() {
super.initState();
_selectedCameras = List.generate(widget.availableCameras.length, (_) => false);
}
String _t(String key) {
return AppTranslations.translate(key, widget.selectedLanguage);
}
@override
Widget build(BuildContext context) {
return AlertDialog(
backgroundColor: Colors.grey[900],
title: Text(
_t('Select Cameras to Spectate'),
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
content: SizedBox(
width: double.maxFinite,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
_t('Choose 1-6 cameras'),
style: TextStyle(
color: Colors.grey[400],
fontSize: 14,
),
),
const SizedBox(height: 16),
Flexible(
child: ListView.builder(
shrinkWrap: true,
itemCount: widget.availableCameras.length,
itemBuilder: (context, index) {
final camera = widget.availableCameras[index];
final cameraIndex = camera['index'] as int;
final cameraIp = camera['ip'] as String;
return CheckboxListTile(
title: Text(
"${_t('Camera')} $cameraIndex",
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
subtitle: Text(
cameraIp,
style: TextStyle(
color: Colors.grey[400],
fontSize: 12,
),
),
value: _selectedCameras[index],
onChanged: (value) {
setState(() {
_selectedCameras[index] = value ?? false;
});
},
activeColor: Colors.grey[800],
checkColor: Colors.white,
tileColor: Colors.grey[850],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 4,
),
);
},
),
),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(
_t('Cancel'),
style: const TextStyle(color: Colors.grey),
),
),
TextButton(
onPressed: _selectedCameras.contains(true)
? () {
final selectedCameras = <Map<String, dynamic>>[];
for (int i = 0; i < _selectedCameras.length; i++) {
if (_selectedCameras[i]) {
selectedCameras.add(widget.availableCameras[i]);
}
}
Navigator.pop(context, selectedCameras);
}
: null,
child: Text(
_t('View Cameras'),
style: TextStyle(
color: _selectedCameras.contains(true)
? Colors.white
: Colors.grey[600],
fontWeight: FontWeight.w600,
),
),
),
],
);
}
}
-248
View File
@@ -1,248 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_mjpeg/flutter_mjpeg.dart';
import '../utils/translations.dart';
class MultiCameraScreen extends StatefulWidget {
final List<Map<String, dynamic>> cameras;
final String selectedLanguage;
const MultiCameraScreen({
super.key,
required this.cameras,
required this.selectedLanguage,
});
@override
State<MultiCameraScreen> createState() => _MultiCameraScreenState();
}
class _MultiCameraScreenState extends State<MultiCameraScreen> {
int? _fullscreenIndex; // null = grid view, index = fullscreen camera
String _t(String key) {
return AppTranslations.translate(key, widget.selectedLanguage);
}
// Calculate grid columns based on camera count
int get _crossAxisCount {
final count = widget.cameras.length;
if (count == 1) return 1;
if (count <= 4) return 2;
return 3; // 5-6 cameras
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
_fullscreenIndex == null
? _t('Multi-Camera View')
: "${_t('Camera')} ${widget.cameras[_fullscreenIndex!]['index']}",
),
backgroundColor: Colors.grey[900],
foregroundColor: Colors.white,
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () {
if (_fullscreenIndex != null) {
setState(() {
_fullscreenIndex = null; // Exit fullscreen first
});
} else {
Navigator.pop(context); // Exit screen
}
},
),
),
backgroundColor: Colors.black,
body: _fullscreenIndex == null
? _buildGridView()
: _buildFullscreenView(_fullscreenIndex!),
);
}
Widget _buildGridView() {
return GridView.builder(
padding: const EdgeInsets.all(8),
itemCount: widget.cameras.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: _crossAxisCount,
mainAxisSpacing: 8,
crossAxisSpacing: 8,
childAspectRatio: 4 / 3, // 4:3 aspect ratio for camera feeds
),
itemBuilder: (context, index) {
return _buildCameraCell(index);
},
);
}
Widget _buildCameraCell(int index) {
final camera = widget.cameras[index];
final cameraIndex = camera['index'] as int;
final cameraIp = camera['ip'] as String;
final streamUrl = cameraIp.startsWith(RegExp(r"https?://"))
? cameraIp
: "http://$cameraIp";
return GestureDetector(
onTap: () {
setState(() {
_fullscreenIndex = index; // Enter fullscreen
});
},
child: Container(
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.grey[700]!, width: 1),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Stack(
children: [
// MJPEG Stream
Mjpeg(
stream: streamUrl,
isLive: true,
fit: BoxFit.contain,
error: (context, error, stackTrace) {
return _buildErrorWidget(cameraIndex);
},
),
// Camera label overlay
Positioned(
top: 8,
left: 8,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: Colors.black.withValues(alpha: 0.6),
borderRadius: BorderRadius.circular(4),
),
child: Text(
"${_t('Camera')} $cameraIndex",
style: const TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
),
),
],
),
),
),
);
}
Widget _buildFullscreenView(int index) {
final camera = widget.cameras[index];
final cameraIndex = camera['index'] as int;
final cameraIp = camera['ip'] as String;
final streamUrl = cameraIp.startsWith(RegExp(r"https?://"))
? cameraIp
: "http://$cameraIp";
return GestureDetector(
onTap: () {
setState(() {
_fullscreenIndex = null; // Exit fullscreen, return to grid
});
},
child: Container(
color: Colors.black,
child: Stack(
children: [
Center(
child: Mjpeg(
stream: streamUrl,
isLive: true,
fit: BoxFit.contain,
error: (context, error, stackTrace) {
return _buildErrorWidget(cameraIndex);
},
),
),
// Back indicator overlay
Positioned(
bottom: 16,
left: 0,
right: 0,
child: Center(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: Colors.black.withValues(alpha: 0.6),
borderRadius: BorderRadius.circular(20),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.touch_app, color: Colors.white, size: 16),
const SizedBox(width: 8),
Text(
_t('Tap to return to grid'),
style:
const TextStyle(color: Colors.white, fontSize: 14),
),
],
),
),
),
),
// Camera label
Positioned(
top: 16,
left: 16,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: Colors.black.withValues(alpha: 0.6),
borderRadius: BorderRadius.circular(6),
),
child: Text(
"${_t('Camera')} $cameraIndex",
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
),
],
),
),
);
}
Widget _buildErrorWidget(int cameraIndex) {
return Container(
color: Colors.black,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.videocam_off, color: Colors.red, size: 32),
const SizedBox(height: 4),
Flexible(
child: Text(
"${_t('Camera')} $cameraIndex\n${_t('Stream unavailable')}",
style: const TextStyle(
color: Colors.white70,
fontSize: 11,
),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
],
),
);
}
}
-15
View File
@@ -1,15 +0,0 @@
import 'package:shared_preferences/shared_preferences.dart';
class SharedPrefsService {
static Future<void> saveCameraIPs(List<String> cameraIPs) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
for (int i = 0; i < 6; i++) {
prefs.setString('camera_$i', cameraIPs[i]);
}
}
static Future<List<String>> loadCameraIPs() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return List.generate(6, (index) => prefs.getString('camera_$index') ?? '');
}
}