diff --git a/lib/main.dart b/lib/main.dart index 3db92b1..1eb45f6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,50 +3,71 @@ import 'package:firebase_core/firebase_core.dart'; import 'firebase_options.dart'; import 'profile.dart'; + import 'pages/login.dart'; import 'pages/settings.dart'; import 'pages/myprofile.dart'; import 'pages/explore.dart'; import 'pages/matches.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import 'auth.dart' as auth; import 'api.dart' as api; import 'log.dart' as log; +// Global notifier for theme mode +final ValueNotifier themeModeNotifier = + ValueNotifier(ThemeMode.light); + void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); + // Load the saved dark mode preference + final prefs = await SharedPreferences.getInstance(); + bool isDarkMode = prefs.getBool('darkMode') ?? false; + themeModeNotifier.value = isDarkMode ? ThemeMode.dark : ThemeMode.light; + runApp(MaterialApp( - theme: ThemeData( - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), - useMaterial3: true, - ), home: Root() )); - //log.i(await api.getMyProfile()); } + class Root extends StatefulWidget { const Root({super.key}); - @override State createState() => RootState(); - + @override + State createState() => RootState(); } + + class RootState extends State { - @override void initState() { - super.initState(); - auth.stateChanges.listen((dynamic _) { - // This is a mild anti-pattern - setState(() {}); - }); - } + @override + void initState() { + super.initState(); + auth.stateChanges.listen((dynamic _) { + // This is a mild anti-pattern + setState(() {}); + }); + } - @override Widget build(BuildContext ctx) { - if (auth.hasUser) { - return App(); - } else { - return LoginPage(); - } + @override + Widget build(BuildContext ctx) { + return ValueListenableBuilder( + valueListenable: themeModeNotifier, + builder: (context, currentTheme, child) { + return MaterialApp( + theme: ThemeData( + colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), + useMaterial3: true, + ), + darkTheme: ThemeData.dark(), + // Here, 'currentTheme' is the local variable provided by the builder + themeMode: currentTheme, + home: auth.hasUser ? App() : LoginPage(), + ); + }, + ); } } diff --git a/lib/pages/settings.dart b/lib/pages/settings.dart index 3b9248e..81f2363 100644 --- a/lib/pages/settings.dart +++ b/lib/pages/settings.dart @@ -1,18 +1,106 @@ -import 'package:flutter/material.dart'; -import '../auth.dart'; -import 'login.dart'; - -class SettingsPage extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Center( - child: ElevatedButton.icon( - icon: Icon(Icons.logout), - label: Text("Logout"), - onPressed: () async { - await signOut(); - }, - ), - ); - } -} +import 'package:flutter/material.dart'; +import '../auth.dart'; +import '../main.dart'; // Import to access themeModeNotifier +import 'package:shared_preferences/shared_preferences.dart'; + +class SettingsPage extends StatelessWidget { + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text("Settings"), + centerTitle: true, + ), + body: SafeArea( + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 20.0, horizontal: 16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // Main settings items at the top + ValueListenableBuilder( + valueListenable: themeModeNotifier, + builder: (context, currentTheme, child) { + bool isDarkMode = currentTheme == ThemeMode.dark; + return SwitchListTile( + title: const Text("Dark Mode"), + value: isDarkMode, + onChanged: (bool value) async { + themeModeNotifier.value = + value ? ThemeMode.dark : ThemeMode.light; + final prefs = await SharedPreferences.getInstance(); + await prefs.setBool('darkMode', value); + }, + ); + }, + ), + ListTile( + leading: const Icon(Icons.info), + title: const Text("About"), + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: const Text("Archnemesis"), + content: SingleChildScrollView( + child: Text( + "By the sting of betrayal and the glory of vendetta, I vow eternal opposition. " + "From petty slights to apocalyptic confrontations, I sharpen my wit as my weapon and fan the flames of rivalry. " + "I shall lurk in shadows of your triumphs, mirror your rise with my own, and forge my legacy in the ashes of your comfort.\n\n" + "Where you stand tall, I crouch in defiance. Where you find peace, I sow glorious chaos. " + "Let every smirk, every success, be a battle cry echoing through our lifelong feud.\n\n" + "For every hero needs a villain. And I am yours.", + ), + ), + actions: [ + TextButton( + onPressed: () => Navigator.of(context).pop(), + child: const Text("OK"), + ), + ], + ); + }, + ); + }, + ), + // Add more settings here if needed + + // Spacer pushes the logout to the bottom + const Spacer(), + + // Logout button at the bottom center + SizedBox( + width: double.infinity, + child: TextButton( + style: TextButton.styleFrom( + // Adjust the background color to your liking. + // You might choose a slightly tinted color or even transparent until pressed. + backgroundColor: Theme.of(context).colorScheme.error, + padding: const EdgeInsets.symmetric(vertical: 16), + ), + onPressed: () async { + await signOut(); + // Navigator.of(context).pushReplacement( + // MaterialPageRoute(builder: (_) => LoginPage()), + // ); + }, + child: Text( + "Logout", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.onError, + // You can also set the color here explicitly, or use Theme.of(context).colorScheme.error, for example. + ), + ), + ), + ) + ], + ), + ), + ), + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index b71d0b1..e033ca5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -38,6 +38,7 @@ dependencies: logger: ^2.5.0 firebase_core: ^3.12.1 google_sign_in: ^6.3.0 + shared_preferences: ^2.5.3 http: ^1.3.0 dev_dependencies: