import 'package:flutter/material.dart'; import '../services/app_settings.dart'; import '../theme/app_theme.dart'; import 'camera_settings_screen.dart'; import 'stream_screen.dart'; /// 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}); 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: [ 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), ), ], ), ), ), ); }, ); }, ); } }