fixes for detection with new target styles
This commit is contained in:
@@ -47,6 +47,20 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
{'code': 'sl', 'name': 'Slovenian', 'flag': '🇸🇮'},
|
||||
];
|
||||
|
||||
String _selectedTarget = 'assets/target.png';
|
||||
final List<String> _availableTargets = [
|
||||
'assets/target.png',
|
||||
'assets/targets/Target1.jpg',
|
||||
'assets/targets/Target2.jpg',
|
||||
'assets/targets/Target3.jpg',
|
||||
'assets/targets/Target4.jpg',
|
||||
'assets/targets/Target5.jpg',
|
||||
'assets/targets/Target6.jpg',
|
||||
'assets/targets/Target7.jpg',
|
||||
'assets/targets/Target11.jpg',
|
||||
'assets/targets/Target14.jpg',
|
||||
'assets/targets/Target15.jpg',
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -54,6 +68,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
_loadCameraIPs();
|
||||
_loadBulletColor();
|
||||
_loadLanguage();
|
||||
_loadSelectedTarget();
|
||||
}
|
||||
|
||||
|
||||
@@ -134,6 +149,29 @@ Future<void> _saveLanguage(String language) async {
|
||||
setState(() => _selectedLanguage = language);
|
||||
}
|
||||
|
||||
Future<void> _loadSelectedTarget() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
String savedTarget = prefs.getString('selectedTarget') ?? 'assets/target.png';
|
||||
|
||||
setState(() {
|
||||
_selectedTarget = savedTarget;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _saveSelectedTarget(String target) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('selectedTarget', target);
|
||||
setState(() => _selectedTarget = target);
|
||||
}
|
||||
|
||||
String _getTargetDisplayName(String targetPath) {
|
||||
if (targetPath == 'assets/target.png') {
|
||||
return 'Default Target';
|
||||
}
|
||||
return targetPath
|
||||
.replaceAll('assets/targets/', '')
|
||||
.replaceAll('.jpg', '');
|
||||
}
|
||||
|
||||
Future<void> _loadCameraIPs() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
@@ -317,6 +355,8 @@ Future<void> _saveLanguage(String language) async {
|
||||
const SizedBox(height: 16),
|
||||
_buildBulletColorSelector(),
|
||||
const SizedBox(height: 16),
|
||||
_buildTargetSelector(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
_buildCameraList(),
|
||||
],
|
||||
@@ -507,6 +547,87 @@ Future<void> _saveLanguage(String language) async {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTargetSelector() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 6, horizontal: 0),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[300],
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withValues(alpha: 0.3),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[900],
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(12),
|
||||
topRight: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 16,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
_t("Select Target"),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Content
|
||||
GestureDetector(
|
||||
onTap: _showTargetPopup,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[300],
|
||||
borderRadius: const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(12),
|
||||
bottomRight: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
_getTargetDisplayName(_selectedTarget),
|
||||
style: const TextStyle(color: Colors.black87, fontSize: 14),
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right, color: Colors.black54),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showLanguagePopup() {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -646,6 +767,130 @@ void _showBulletColorPopup() {
|
||||
);
|
||||
}
|
||||
|
||||
void _showTargetPopup() {
|
||||
String previewTarget = _selectedTarget;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, innerSetState) {
|
||||
|
||||
return Dialog(
|
||||
backgroundColor: Colors.grey[900],
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
_t("Select Target"),
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// Image Preview
|
||||
Container(
|
||||
width: 200,
|
||||
height: 200,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.white24),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Image.asset(
|
||||
previewTarget,
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return Container(
|
||||
color: Colors.grey[800],
|
||||
child: const Center(
|
||||
child: Icon(Icons.image_not_supported, color: Colors.white54),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// Target List
|
||||
SizedBox(
|
||||
width: double.maxFinite,
|
||||
height: 300,
|
||||
child: ListView(
|
||||
children: _availableTargets.map((targetPath) {
|
||||
final isSelected = targetPath == previewTarget;
|
||||
final displayName = _getTargetDisplayName(targetPath);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12.0),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
innerSetState(() => previewTarget = targetPath);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: isSelected
|
||||
? _getColorFromName(_selectedBulletColor)
|
||||
: Colors.grey[800],
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: Text(displayName),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// Action Buttons
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
await _saveSelectedTarget(previewTarget);
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _getColorFromName(_selectedBulletColor),
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: Text(_t("Apply")),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: Text(_t("Cancel"), style: const TextStyle(color: Colors.white70)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCameraList() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 6, horizontal: 0),
|
||||
|
||||
Reference in New Issue
Block a user