feat: Add theme customization options in settings screen and update app theme logic
This commit is contained in:
@@ -9,11 +9,15 @@ class SettingsScreen extends StatefulWidget {
|
||||
required this.onDeleteAllData,
|
||||
required this.onBackToHome,
|
||||
required this.onForceSync,
|
||||
required this.currentSeedColor,
|
||||
required this.onThemeColorSelected,
|
||||
});
|
||||
|
||||
final Future<void> Function() onDeleteAllData;
|
||||
final VoidCallback onBackToHome;
|
||||
final Future<void> Function() onForceSync;
|
||||
final Color currentSeedColor;
|
||||
final Future<void> Function(Color color) onThemeColorSelected;
|
||||
|
||||
@override
|
||||
State<SettingsScreen> createState() => _SettingsScreenState();
|
||||
@@ -22,11 +26,22 @@ class SettingsScreen extends StatefulWidget {
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
bool _isBusy = false;
|
||||
bool _isSyncing = false;
|
||||
bool _isThemeSaving = false;
|
||||
final TextEditingController _endpointController = TextEditingController();
|
||||
final TextEditingController _encryptionKeyController = TextEditingController();
|
||||
bool _endpointLoading = true;
|
||||
bool _encryptionKeyLoading = false;
|
||||
bool _encryptionKeyVisible = false;
|
||||
late Color _selectedSeedColor;
|
||||
|
||||
static const List<Color> _themeColorOptions = <Color>[
|
||||
Colors.amber,
|
||||
Colors.blue,
|
||||
Colors.teal,
|
||||
Colors.green,
|
||||
Colors.pink,
|
||||
Colors.purple,
|
||||
];
|
||||
|
||||
Future<void> _confirmAndDeleteAll() async {
|
||||
final bool? confirmed = await showDialog<bool>(
|
||||
@@ -100,12 +115,56 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _selectThemeColor(Color color) async {
|
||||
if (_isThemeSaving || _selectedSeedColor == color) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Color previousColor = _selectedSeedColor;
|
||||
setState(() {
|
||||
_selectedSeedColor = color;
|
||||
_isThemeSaving = true;
|
||||
});
|
||||
|
||||
try {
|
||||
await widget.onThemeColorSelected(color);
|
||||
} catch (error) {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_selectedSeedColor = previousColor;
|
||||
});
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('No se pudo guardar el color: $error')),
|
||||
);
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isThemeSaving = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedSeedColor = widget.currentSeedColor;
|
||||
_loadEndpoint();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant SettingsScreen oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.currentSeedColor != widget.currentSeedColor &&
|
||||
widget.currentSeedColor != _selectedSeedColor) {
|
||||
_selectedSeedColor = widget.currentSeedColor;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadEndpoint() async {
|
||||
final String endpoint = await ApiConfig.getEndpoint();
|
||||
if (!mounted) return;
|
||||
@@ -160,6 +219,58 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildThemeColorButton(Color color) {
|
||||
final bool isSelected = _selectedSeedColor.value == color.value;
|
||||
final Color foregroundColor =
|
||||
ThemeData.estimateBrightnessForColor(color) == Brightness.dark
|
||||
? Colors.white
|
||||
: Colors.black;
|
||||
|
||||
return Semantics(
|
||||
button: true,
|
||||
selected: isSelected,
|
||||
label: 'Color ${color.value.toRadixString(16)}',
|
||||
child: Tooltip(
|
||||
message: isSelected ? 'Color actual' : 'Usar este color',
|
||||
child: InkWell(
|
||||
onTap: _isThemeSaving ? null : () => _selectThemeColor(color),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: isSelected ? Colors.white : Colors.white24,
|
||||
width: isSelected ? 2.5 : 1.2,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.25),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
if (isSelected)
|
||||
Icon(
|
||||
Icons.check,
|
||||
size: 22,
|
||||
color: foregroundColor,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_endpointController.dispose();
|
||||
@@ -296,11 +407,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
child: Text('Forzar sincronizacion total:'),
|
||||
),
|
||||
ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.amber,
|
||||
foregroundColor: Colors.black,
|
||||
textStyle: const TextStyle(fontWeight: FontWeight.w700),
|
||||
),
|
||||
onPressed: (_isBusy || _isSyncing) ? null : _forceSync,
|
||||
icon: _isSyncing
|
||||
? const SizedBox(
|
||||
@@ -314,6 +420,17 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Text('Color del esquema'),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 12,
|
||||
runSpacing: 12,
|
||||
children: [
|
||||
for (final Color color in _themeColorOptions)
|
||||
_buildThemeColorButton(color),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Text('API endpoint (ej: http://localhost:3000/api)'),
|
||||
const SizedBox(height: 8),
|
||||
_buildResponsiveInputActionsRow(
|
||||
|
||||
Reference in New Issue
Block a user