added some camera changes and included IOS support

This commit is contained in:
2025-10-18 19:02:26 +02:00
parent 2e3a69a23e
commit be9b13fb15
7 changed files with 766 additions and 80 deletions
+233 -13
View File
@@ -24,6 +24,10 @@ class _CameraScreenState extends State<CameraScreen> {
int _numberOfBullets = 5;
String _selectedLanguage = 'English';
// Brightness and contrast controls
double _brightness = 0.0; // -1.0 to 1.0
double _contrast = 1.0; // 0.0 to 2.0
@override
void initState() {
super.initState();
@@ -31,9 +35,24 @@ class _CameraScreenState extends State<CameraScreen> {
_initCamera();
_loadBulletColor(); // 👈
_loadLanguage();
_loadBrightnessContrast();
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) {
return AppTranslations.translate(key, _selectedLanguage);
}
@@ -240,6 +259,175 @@ Color _getColorFromName(String colorName) {
}
void _showHelpDialog() {
showDialog(
context: context,
builder: (BuildContext context) {
return Dialog(
backgroundColor: Colors.grey[900],
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_t('Help'),
style: const TextStyle(color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold),
),
const SizedBox(height: 20),
_buildHelpItem(Icons.camera_alt, _t('Tap camera button to capture and detect bullets')),
const SizedBox(height: 12),
_buildHelpItem(Icons.filter_9_plus, _t('Bottom left number: Set expected bullet count (1-5)')),
const SizedBox(height: 12),
_buildHelpItem(Icons.brightness_6, _t('Sun icon: Adjust brightness and contrast for better visibility')),
const SizedBox(height: 12),
_buildHelpItem(Icons.crop_square, _t('Align target inside the square frame')),
const SizedBox(height: 20),
Center(
child: ElevatedButton(
onPressed: () => Navigator.of(context).pop(),
style: ElevatedButton.styleFrom(
backgroundColor: _bulletColor,
foregroundColor: Colors.white,
),
child: Text(_t('Got it!')),
),
),
],
),
),
);
},
);
}
Widget _buildHelpItem(IconData icon, String text) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(icon, color: _bulletColor, size: 20),
const SizedBox(width: 12),
Expanded(
child: Text(
text,
style: const TextStyle(color: Colors.white, fontSize: 14),
),
),
],
);
}
void _showBrightnessContrastDialog() {
showDialog(
context: context,
builder: (BuildContext context) {
return StatefulBuilder(
builder: (context, setDialogState) {
return Dialog(
backgroundColor: Colors.grey[900],
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
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,
children: [
Text(
'${_t('Brightness')}: ${(_brightness * 100).toInt()}',
style: const TextStyle(color: Colors.white, fontSize: 16),
),
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) {
setState(() {
@@ -274,26 +462,58 @@ Color _getColorFromName(String colorName) {
),
centerTitle: true,
actions: [
// Display the selected bullet count
IconButton(
icon: Text(
'$_numberOfBullets',
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
onPressed: _showBulletDialog, // Show dialog on tap
icon: const Icon(Icons.help_outline, color: Colors.white),
onPressed: _showHelpDialog,
),
const SizedBox(width: 16), // Space after the number
const SizedBox(width: 16),
],
),
bottomNavigationBar: BottomAppBar(
color: Colors.grey[900],
shape: const CircularNotchedRectangle(),
notchMargin: 8.0,
child: SizedBox(height: 60),
child: SizedBox(
height: 60,
child: Row(
children: [
// Left - Bullet count (just number)
Expanded(
child: Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.only(left: 16.0),
child: InkWell(
onTap: _showBulletDialog,
child: Text(
'$_numberOfBullets',
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
),
),
// Center space for FAB
const SizedBox(width: 80),
// Right section - Brightness
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
IconButton(
icon: const Icon(Icons.brightness_6, color: Colors.white, size: 24),
onPressed: _showBrightnessContrastDialog,
),
],
),
),
],
),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
@@ -327,7 +547,7 @@ Color _getColorFromName(String colorName) {
height: screenSize.width * 0.9,
decoration: BoxDecoration(
border: Border.all(
color: _bulletColor.withOpacity(0.9),
color: _bulletColor.withValues(alpha: 0.9),
width: 3,
),
),