import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:provider/provider.dart'; import 'package:share_plus/share_plus.dart'; import 'package:url_launcher/url_launcher.dart'; import '../services/hydration_service.dart'; import '../widgets/glass_card.dart'; import 'feedback_screen.dart'; class SettingsScreen extends StatelessWidget { const SettingsScreen({super.key}); // 隐私政策URL static const String privacyPolicyUrl = 'https://biofluxsmart.bitbucket.io/privacy.html'; @override Widget build(BuildContext context) { final service = context.watch(); final color = service.dynamicWaterColor; return Scaffold( body: SafeArea( child: ListView( padding: const EdgeInsets.all(20), children: [ Text( "Settings", style: GoogleFonts.montserrat( fontSize: 28, fontWeight: FontWeight.bold, ), ), const SizedBox(height: 20), // Personalization _buildSectionHeader("Personalization"), GlassCard( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Icon(Icons.calculate, color: color), const SizedBox(width: 10), Text( "Metabolic Goals", style: GoogleFonts.montserrat( fontWeight: FontWeight.bold, ), ), ], ), const Divider(height: 20), _buildSliderRow( label: "Weight", value: "${service.weight.toInt()} kg", slider: Slider( value: service.weight, min: 30, max: 150, activeColor: color, onChanged: (v) => service.updateSettings(weight: v), ), ), _buildSliderRow( label: "Workout", value: "${service.workoutMinutes.toInt()} min", slider: Slider( value: service.workoutMinutes, min: 0, max: 180, activeColor: color, onChanged: (v) => service.updateSettings(workout: v), ), ), Padding( padding: const EdgeInsets.only(top: 8.0), child: Center( child: Text( "Target: ${service.dailyGoal.toInt()} ml", style: GoogleFonts.montserrat( fontSize: 16, color: color, fontWeight: FontWeight.bold, ), ), ), ), ], ), ), const SizedBox(height: 20), // Preferences _buildSectionHeader("Preferences"), GlassCard( padding: EdgeInsets.zero, child: Column( children: [ SwitchListTile( title: Text("Smart Reminders", style: GoogleFonts.lato()), subtitle: Text( "Notify when hydration drops", style: GoogleFonts.lato(fontSize: 12, color: Colors.grey), ), value: service.remindersEnabled, activeColor: color, onChanged: (v) => service.updateSettings(reminders: v), ), const Divider(height: 1, indent: 16, endIndent: 16), ], ), ), const SizedBox(height: 20), // Support _buildSectionHeader("Support"), GlassCard( padding: EdgeInsets.zero, child: Column( children: [ ListTile( leading: Icon( Icons.share_outlined, color: Colors.grey.shade600, size: 20, ), title: Text("Share App", style: GoogleFonts.lato()), trailing: const Icon( Icons.chevron_right, size: 18, color: Colors.black26, ), onTap: () { Share.share( 'Check out BioFlux - The Metabolic Hydration Tracker! Stay fluid.', ); }, ), const Divider(height: 1, indent: 16, endIndent: 16), ListTile( leading: Icon( Icons.chat_bubble_outline, color: Colors.grey.shade600, size: 20, ), title: Text("Send Feedback", style: GoogleFonts.lato()), trailing: const Icon( Icons.chevron_right, size: 18, color: Colors.black26, ), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (_) => const FeedbackScreen(), ), ); }, ), const Divider(height: 1, indent: 16, endIndent: 16), ListTile( leading: Icon( Icons.lock_outline, color: Colors.grey.shade600, size: 20, ), title: Text("Privacy Policy", style: GoogleFonts.lato()), trailing: const Icon( Icons.chevron_right, size: 18, color: Colors.black26, ), onTap: () => _launchPrivacyPolicy(context), ), const Divider(height: 1, indent: 16, endIndent: 16), ListTile( leading: Icon( Icons.info_outline, color: Colors.grey.shade600, size: 20, ), title: Text("About BioFlux", style: GoogleFonts.lato()), trailing: const Icon( Icons.chevron_right, size: 18, color: Colors.black26, ), onTap: () => _showAboutDialog(context), ), ], ), ), const SizedBox(height: 100), ], ), ), ); } Widget _buildSectionHeader(String title) { return Padding( padding: const EdgeInsets.only(left: 8, bottom: 8), child: Text( title.toUpperCase(), style: GoogleFonts.montserrat( fontSize: 12, fontWeight: FontWeight.bold, color: Colors.grey.shade500, letterSpacing: 1.2, ), ), ); } Widget _buildSliderRow({ required String label, required String value, required Widget slider, }) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(label, style: GoogleFonts.lato()), Text(value, style: GoogleFonts.lato(fontWeight: FontWeight.bold)), ], ), SizedBox(height: 30, child: slider), ], ); } // 打开隐私政策网页 Future _launchPrivacyPolicy(BuildContext context) async { try { final Uri url = Uri.parse(privacyPolicyUrl); if (await canLaunchUrl(url)) { await launchUrl(url, mode: LaunchMode.externalApplication); } else { if (context.mounted) { _showErrorDialog(context, 'Unable to open privacy policy'); } } } catch (e) { if (context.mounted) { _showErrorDialog(context, 'Error opening privacy policy: $e'); } } } // 显示关于应用对话框 void _showAboutDialog(BuildContext context) { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(20), ), title: Row( children: [ Container( width: 40, height: 40, decoration: BoxDecoration( gradient: LinearGradient( colors: [Colors.blue.shade400, Colors.cyan.shade300], begin: Alignment.topLeft, end: Alignment.bottomRight, ), borderRadius: BorderRadius.circular(10), ), child: const Icon( Icons.water_drop, color: Colors.white, size: 24, ), ), const SizedBox(width: 12), Text( "BioFlux", style: GoogleFonts.montserrat( fontSize: 24, fontWeight: FontWeight.bold, ), ), ], ), content: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( "Smart Hydration Tracker", style: GoogleFonts.lato( fontSize: 16, fontWeight: FontWeight.w600, color: Colors.grey.shade700, ), ), const SizedBox(height: 16), Text( "Version 1.0.0", style: GoogleFonts.lato( fontSize: 14, color: Colors.grey.shade600, ), ), const SizedBox(height: 16), Text( "BioFlux helps you maintain optimal hydration levels based on your metabolic needs. Track your daily water intake, set personalized goals, and receive smart reminders to stay healthy and hydrated.", style: GoogleFonts.lato(fontSize: 14, height: 1.5), ), const SizedBox(height: 16), Container( padding: const EdgeInsets.all(12), decoration: BoxDecoration( color: Colors.blue.shade50, borderRadius: BorderRadius.circular(8), ), child: Row( children: [ Icon(Icons.favorite, color: Colors.red.shade400, size: 16), const SizedBox(width: 8), Expanded( child: Text( "Made with care for your health", style: GoogleFonts.lato( fontSize: 12, color: Colors.grey.shade700, ), ), ), ], ), ), ], ), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(), child: Text( "Close", style: GoogleFonts.lato(fontWeight: FontWeight.w600), ), ), ], ); }, ); } // 显示错误对话框 void _showErrorDialog(BuildContext context, String message) { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: Text( "Error", style: GoogleFonts.montserrat(fontWeight: FontWeight.bold), ), content: Text(message, style: GoogleFonts.lato()), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(), child: Text( "OK", style: GoogleFonts.lato(fontWeight: FontWeight.w600), ), ), ], ); }, ); } }