2026-02-27 23:35:54 +01:00
// ===========================================================================
// FILE: lib/ui/settings/settings_screen.dart
// ===========================================================================
import ' package:flutter/material.dart ' ;
import ' package:provider/provider.dart ' ;
import ' ../../core/theme_manager.dart ' ;
import ' ../../core/app_colors.dart ' ;
2026-03-01 20:59:06 +01:00
import ' ../../services/storage_service.dart ' ;
2026-02-27 23:35:54 +01:00
2026-03-01 20:59:06 +01:00
class SettingsScreen extends StatefulWidget {
2026-02-27 23:35:54 +01:00
const SettingsScreen ( { super . key } ) ;
2026-03-01 20:59:06 +01:00
@ override
State < SettingsScreen > createState ( ) = > _SettingsScreenState ( ) ;
}
class _SettingsScreenState extends State < SettingsScreen > {
2026-02-27 23:35:54 +01:00
@ override
Widget build ( BuildContext context ) {
final themeManager = context . watch < ThemeManager > ( ) ;
final theme = themeManager . currentColors ;
2026-03-01 20:59:06 +01:00
int playerLevel = StorageService . instance . playerLevel ;
2026-02-27 23:35:54 +01:00
return Scaffold (
backgroundColor: theme . background ,
appBar: AppBar (
title: Text ( " SELEZIONA TEMA " , style: TextStyle ( fontWeight: FontWeight . bold , color: theme . text ) ) ,
backgroundColor: Colors . transparent ,
elevation: 0 ,
iconTheme: IconThemeData ( color: theme . text ) ,
) ,
body: ListView (
padding: const EdgeInsets . all ( 20 ) ,
children: [
_ThemeCard (
2026-03-13 22:00:00 +01:00
title: " Quaderno (Doodle) " ,
subtitle: " Sfondo a quadretti, tratto a penna " ,
type: AppThemeType . doodle ,
previewColors: AppColors . doodle ,
2026-03-01 20:59:06 +01:00
requiredLevel: 1 ,
currentLevel: playerLevel ,
) ,
const SizedBox ( height: 15 ) ,
_ThemeCard (
title: " Legno & Fiammiferi " ,
subtitle: " Tavolo di legno, linee come fiammiferi " ,
type: AppThemeType . wood ,
previewColors: AppColors . wood ,
requiredLevel: 3 ,
currentLevel: playerLevel ,
2026-02-27 23:35:54 +01:00
) ,
const SizedBox ( height: 15 ) ,
_ThemeCard (
title: " Cyberpunk " ,
subtitle: " Nero profondo, luci al neon " ,
type: AppThemeType . cyberpunk ,
previewColors: AppColors . cyberpunk ,
2026-03-01 20:59:06 +01:00
requiredLevel: 7 ,
currentLevel: playerLevel ,
2026-02-27 23:35:54 +01:00
) ,
const SizedBox ( height: 15 ) ,
_ThemeCard (
2026-03-01 20:59:06 +01:00
title: " 8-Bit Arcade " ,
subtitle: " Sale giochi, fosfori verdi e pixel " ,
type: AppThemeType . arcade ,
previewColors: AppColors . arcade ,
requiredLevel: 10 ,
currentLevel: playerLevel ,
) ,
const SizedBox ( height: 15 ) ,
_ThemeCard (
title: " Grimorio " ,
subtitle: " Incantesimi antichi, rune magiche " ,
type: AppThemeType . grimorio ,
previewColors: AppColors . grimorio ,
requiredLevel: 15 ,
currentLevel: playerLevel ,
2026-02-27 23:35:54 +01:00
) ,
] ,
) ,
) ;
}
}
class _ThemeCard extends StatelessWidget {
final String title ;
final String subtitle ;
final AppThemeType type ;
final ThemeColors previewColors ;
2026-03-01 20:59:06 +01:00
final int requiredLevel ;
final int currentLevel ;
2026-02-27 23:35:54 +01:00
2026-03-01 20:59:06 +01:00
const _ThemeCard ( {
required this . title ,
required this . subtitle ,
required this . type ,
required this . previewColors ,
required this . requiredLevel ,
required this . currentLevel ,
} ) ;
2026-02-27 23:35:54 +01:00
@ override
Widget build ( BuildContext context ) {
final themeManager = context . watch < ThemeManager > ( ) ;
bool isSelected = themeManager . currentThemeType = = type ;
2026-03-01 20:59:06 +01:00
bool isLocked = currentLevel < requiredLevel ;
2026-02-27 23:35:54 +01:00
return GestureDetector (
onTap: ( ) {
2026-03-01 20:59:06 +01:00
if ( isLocked ) {
ScaffoldMessenger . of ( context ) . showSnackBar (
SnackBar (
content: Text ( " Gioca per raggiungere il Liv. $ requiredLevel e sbloccare questo tema! " , style: const TextStyle ( fontWeight: FontWeight . bold , color: Colors . white ) ) ,
backgroundColor: Colors . redAccent ,
behavior: SnackBarBehavior . floating ,
shape: RoundedRectangleBorder ( borderRadius: BorderRadius . circular ( 10 ) ) ,
duration: const Duration ( seconds: 2 ) ,
)
) ;
return ;
}
2026-02-27 23:35:54 +01:00
themeManager . setTheme ( type ) ;
Navigator . pop ( context ) ;
} ,
child: AnimatedContainer (
duration: const Duration ( milliseconds: 300 ) ,
padding: const EdgeInsets . all ( 20 ) ,
decoration: BoxDecoration (
2026-03-01 20:59:06 +01:00
color: isLocked ? previewColors . background . withOpacity ( 0.4 ) : previewColors . background ,
2026-02-27 23:35:54 +01:00
borderRadius: BorderRadius . circular ( 20 ) ,
border: Border . all (
2026-03-01 20:59:06 +01:00
color: isSelected
? previewColors . playerBlue
: ( isLocked ? Colors . grey . withOpacity ( 0.3 ) : previewColors . gridLine . withOpacity ( 0.5 ) ) ,
2026-02-27 23:35:54 +01:00
width: isSelected ? 4 : 2 ,
) ,
boxShadow: isSelected ? [ BoxShadow ( color: previewColors . playerBlue . withOpacity ( 0.4 ) , blurRadius: 10 , spreadRadius: 2 ) ] : [ ] ,
) ,
2026-03-01 20:59:06 +01:00
child: Stack (
alignment: Alignment . center ,
2026-02-27 23:35:54 +01:00
children: [
2026-03-01 20:59:06 +01:00
Opacity (
opacity: isLocked ? 0.25 : 1.0 ,
child: Row (
2026-02-27 23:35:54 +01:00
children: [
2026-03-01 20:59:06 +01:00
Expanded (
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
Text ( title , style: TextStyle ( fontSize: 22 , fontWeight: FontWeight . bold , color: previewColors . text ) ) ,
Text ( subtitle , style: TextStyle ( fontSize: 14 , color: previewColors . text . withOpacity ( 0.7 ) ) ) ,
] ,
) ,
) ,
2026-03-13 22:00:00 +01:00
Container ( width: 20 , height: 20 , decoration: BoxDecoration ( color: previewColors . playerRed , shape: BoxShape . circle , boxShadow: [ BoxShadow ( color: previewColors . playerRed . withOpacity ( 0.5 ) , blurRadius: 4 ) ] ) ) ,
2026-03-01 20:59:06 +01:00
const SizedBox ( width: 10 ) ,
2026-03-13 22:00:00 +01:00
Container ( width: 20 , height: 20 , decoration: BoxDecoration ( color: previewColors . playerBlue , shape: BoxShape . circle , boxShadow: [ BoxShadow ( color: previewColors . playerBlue . withOpacity ( 0.5 ) , blurRadius: 4 ) ] ) ) ,
2026-02-27 23:35:54 +01:00
] ,
) ,
) ,
2026-03-01 20:59:06 +01:00
if ( isLocked )
Container (
padding: const EdgeInsets . symmetric ( horizontal: 16 , vertical: 8 ) ,
decoration: BoxDecoration (
color: Colors . black . withOpacity ( 0.85 ) ,
borderRadius: BorderRadius . circular ( 20 ) ,
border: Border . all ( color: Colors . white . withOpacity ( 0.2 ) , width: 1.5 ) ,
boxShadow: [ BoxShadow ( color: Colors . black . withOpacity ( 0.5 ) , blurRadius: 10 , offset: const Offset ( 0 , 4 ) ) ] ,
) ,
child: Row (
mainAxisSize: MainAxisSize . min ,
children: [
const Icon ( Icons . lock_rounded , color: Colors . white , size: 20 ) ,
const SizedBox ( width: 8 ) ,
Text (
" LIV. $ requiredLevel " ,
style: const TextStyle ( color: Colors . white , fontWeight: FontWeight . w900 , fontSize: 16 , letterSpacing: 2 )
) ,
] ,
) ,
) ,
2026-02-27 23:35:54 +01:00
] ,
) ,
) ,
) ;
}
}