import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'login_screen.dart'; import 'desktop_login_screen.dart'; import '../core/theme_manager.dart'; import 'privacy_policy_screen.dart'; // new import import '../core/app_decoration.dart'; class SettingsScreen extends StatefulWidget { const SettingsScreen({Key? key}) : super(key: key); @override State createState() => _SettingsScreenState(); } class _SettingsScreenState extends State { bool _notifications = true; String _appVersion = '1.2(p)'; @override void initState() { super.initState(); _loadPreferences(); } Future _loadPreferences() async { final prefs = await SharedPreferences.getInstance(); setState(() { _notifications = prefs.getBool('reminders_enabled') ?? true; // app version may come from pubspec or preferences; kept static otherwise }); } Future _saveNotifications(bool value) async { final prefs = await SharedPreferences.getInstance(); await prefs.setBool('reminders_enabled', value); setState(() => _notifications = value); } Future _confirmLogout() async { final should = await showDialog( context: context, builder: (ctx) { return AlertDialog( title: const Text('Logout'), content: const Text('Are you sure you want to logout? This will clear saved login data.'), actions: [ TextButton(onPressed: () => Navigator.of(ctx).pop(false), child: const Text('Cancel')), ElevatedButton(onPressed: () => Navigator.of(ctx).pop(true), child: const Text('Logout')), ], ); }, ); if (should == true) { await _performLogout(); } } Future _performLogout() async { final prefs = await SharedPreferences.getInstance(); await prefs.remove('username'); await prefs.remove('email'); await prefs.remove('profileImage'); // Decide which login screen to show depending on current window width final double width = MediaQuery.of(context).size.width; const double desktopBreakpoint = 820; // same breakpoint used elsewhere final bool isDesktop = width >= desktopBreakpoint; // Navigate and remove all previous routes Navigator.of(context).pushAndRemoveUntil( MaterialPageRoute( builder: (_) => isDesktop ? const DesktopLoginScreen() : const LoginScreen(), ), (route) => false, ); } Widget _buildTile({required IconData icon, required String title, String? subtitle, VoidCallback? onTap}) { return Container( margin: const EdgeInsets.symmetric(vertical: 6), decoration: BoxDecoration( color: Theme.of(context).cardColor, borderRadius: BorderRadius.circular(12), boxShadow: const [BoxShadow(color: Colors.black12, blurRadius: 6, offset: Offset(0, 4))], ), child: ListTile( leading: Container( width: 44, height: 44, decoration: BoxDecoration(color: Theme.of(context).scaffoldBackgroundColor, borderRadius: BorderRadius.circular(10)), child: Icon(icon, color: const Color(0xFF0B63D6)), ), title: Text(title, style: const TextStyle(fontWeight: FontWeight.w600)), subtitle: subtitle != null ? Text(subtitle) : null, onTap: onTap, contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), ), ); } @override Widget build(BuildContext context) { const primary = Color(0xFF0B63D6); return Scaffold( backgroundColor: Theme.of(context).scaffoldBackgroundColor, body: SafeArea( child: Column( children: [ // Header Container( width: double.infinity, padding: const EdgeInsets.fromLTRB(20, 18, 20, 18), decoration: AppDecoration.blueGradient.copyWith( borderRadius: const BorderRadius.only(bottomLeft: Radius.circular(24), bottomRight: Radius.circular(24)), ), child: Row( children: [ const Expanded(child: Text('Settings', style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w600))), InkWell( onTap: () => ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Help tapped (demo)'))), child: Container( width: 40, height: 40, decoration: BoxDecoration(color: Colors.white24, borderRadius: BorderRadius.circular(10)), child: const Icon(Icons.help_outline, color: Colors.white), ), ), ], ), ), const SizedBox(height: 18), // Content Expanded( child: SingleChildScrollView( padding: const EdgeInsets.fromLTRB(18, 0, 18, 24), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // Account const Text('Account', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)), const SizedBox(height: 12), _buildTile( icon: Icons.person, title: 'Edit Profile', subtitle: 'Change username, email or photo', onTap: () { ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Open Profile tab (demo)'))); }, ), const SizedBox(height: 12), // Preferences const Text('Preferences', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)), const SizedBox(height: 12), // Reminders switch wrapped in card-like container Container( margin: const EdgeInsets.symmetric(vertical: 6), decoration: BoxDecoration( color: Theme.of(context).cardColor, borderRadius: BorderRadius.circular(12), boxShadow: const [BoxShadow(color: Colors.black12, blurRadius: 6, offset: Offset(0, 4))], ), child: SwitchListTile( tileColor: Theme.of(context).cardColor, contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4), value: _notifications, onChanged: (v) => _saveNotifications(v), title: const Text('Reminders'), secondary: const Icon(Icons.notifications, color: primary), ), ), const SizedBox(height: 8), // Dark Mode switch wrapped in card-like container and hooked to ThemeManager Container( margin: const EdgeInsets.symmetric(vertical: 6), decoration: BoxDecoration( color: Theme.of(context).cardColor, borderRadius: BorderRadius.circular(12), boxShadow: const [BoxShadow(color: Colors.black12, blurRadius: 6, offset: Offset(0, 4))], ), child: ValueListenableBuilder( valueListenable: ThemeManager.themeMode, builder: (context, mode, _) { final isDark = mode == ThemeMode.dark; return SwitchListTile( tileColor: Theme.of(context).cardColor, contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4), value: isDark, onChanged: (v) => ThemeManager.setThemeMode(v ? ThemeMode.dark : ThemeMode.light), title: const Text('Dark Mode'), secondary: const Icon(Icons.dark_mode, color: primary), ); }, ), ), const SizedBox(height: 18), // About const Text('About', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)), const SizedBox(height: 12), _buildTile(icon: Icons.info_outline, title: 'App Version', subtitle: _appVersion, onTap: () {}), const SizedBox(height: 12), // Privacy Policy tile now navigates to PrivacyPolicyScreen _buildTile( icon: Icons.privacy_tip_outlined, title: 'Privacy Policy', subtitle: 'Demo app', onTap: () { Navigator.of(context).push(MaterialPageRoute(builder: (_) => const PrivacyPolicyScreen())); }, ), const SizedBox(height: 24), // Logout area Center( child: Column( children: [ ElevatedButton( onPressed: _confirmLogout, style: ElevatedButton.styleFrom( backgroundColor: primary, padding: const EdgeInsets.symmetric(horizontal: 28, vertical: 14), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)), ), child: const Text('Logout', style: TextStyle(color: Colors.white)), ), const SizedBox(height: 12), const Text('Logging out will return you to the login screen.', style: TextStyle(color: Colors.black54, fontSize: 12)), ], ), ), const SizedBox(height: 32), ], ), ), ), ], ), ), ); } }