import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../services/app_state.dart'; class SettingsScreen extends StatefulWidget { const SettingsScreen({super.key}); @override State createState() => _SettingsScreenState(); } class _SettingsScreenState extends State { bool _changing = false; String? _error; Future _chooseFolder() async { setState(() => _error = null); final selectedPath = await FilePicker.platform.getDirectoryPath( dialogTitle: 'Choose a folder for receipts and data', ); if (selectedPath == null || !mounted) return; setState(() => _changing = true); try { await context.read().changeSaveDirectory(selectedPath); } catch (e) { setState(() => _error = 'Could not switch to that folder: $e'); } finally { if (mounted) setState(() => _changing = false); } } @override Widget build(BuildContext context) { final appState = context.watch(); final saveDir = appState.storage.saveDirectory.path; return Scaffold( appBar: AppBar(title: const Text('Settings')), body: ListView( padding: const EdgeInsets.all(16), children: [ Card( child: Padding( padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('Save Location', style: Theme.of(context).textTheme.titleMedium), const SizedBox(height: 8), Text( 'Receipt photos and the data file are stored here:', style: Theme.of(context).textTheme.bodyMedium, ), const SizedBox(height: 4), SelectableText( saveDir, style: Theme.of(context).textTheme.bodySmall?.copyWith( fontFamily: 'monospace', ), ), const SizedBox(height: 16), if (_error != null) ...[ Text(_error!, style: TextStyle(color: Theme.of(context).colorScheme.error)), const SizedBox(height: 8), ], FilledButton.icon( onPressed: _changing ? null : _chooseFolder, icon: _changing ? const SizedBox( height: 16, width: 16, child: CircularProgressIndicator(strokeWidth: 2), ) : const Icon(Icons.folder_open), label: const Text('Choose Folder'), ), ], ), ), ), const SizedBox(height: 16), Card( child: Padding( padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('Summary', style: Theme.of(context).textTheme.titleMedium), const SizedBox(height: 8), Text('${appState.vehicles.length} vehicle(s)'), Text('${appState.fuelEntries.length} fuel entries'), Text('${appState.totalGallonsAllVehicles.toStringAsFixed(3)} total gallons logged'), ], ), ), ), ], ), ); } }