From 8c8a52294d6370bc7ffb8d5115a5f3eb71847ce2 Mon Sep 17 00:00:00 2001 From: Erik Burgess Date: Wed, 16 Apr 2025 01:17:10 -0700 Subject: [PATCH 1/4] adding darkmode and making settings screen prettier --- lib/main.dart | 33 ++++++++++++--- lib/settings.dart | 105 +++++++++++++++++++++++++++++++++++++++++----- pubspec.yaml | 1 + 3 files changed, 123 insertions(+), 16 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 780dd8e..471a5ea 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,10 +6,22 @@ import 'matches.dart'; import 'login.dart'; import 'api.dart'; import 'settings.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + + +// Global notifier for theme mode +final ValueNotifier themeModeNotifier = + ValueNotifier(ThemeMode.light); void main() async { WidgetsFlutterBinding.ensureInitialized(); await init(); // this calls Firebase.initializeApp under the hood + + // 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(Root()); } @@ -18,12 +30,21 @@ class Root extends StatelessWidget { @override Widget build(BuildContext ctx) { - return MaterialApp( - theme: ThemeData( - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), - useMaterial3: true, - ), - home: LoginPage()); + 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: LoginPage(), + ); + }, + ); } } diff --git a/lib/settings.dart b/lib/settings.dart index cfc969d..6a5f306 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -1,22 +1,107 @@ import 'package:flutter/material.dart'; import 'auth_service.dart'; import 'login.dart'; +import '../main.dart'; // Import to access themeModeNotifier +import 'package:shared_preferences/shared_preferences.dart'; class SettingsScreen extends StatelessWidget { final AuthService authService = AuthService(); @override Widget build(BuildContext context) { - return Center( - child: ElevatedButton.icon( - icon: Icon(Icons.logout), - label: Text("Logout"), - onPressed: () async { - await authService.signOut(); - Navigator.of(context).pushReplacement( - MaterialPageRoute(builder: (_) => LoginPage()), - ); - }, + 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 authService.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 a7aad27..a84b63c 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 dev_dependencies: flutter_test: From 15f6a52cc3d6978f112010da276165a5db0e343d Mon Sep 17 00:00:00 2001 From: Erik Burgess Date: Thu, 17 Apr 2025 01:27:50 -0700 Subject: [PATCH 2/4] fixing settings page conflicts --- lib/main.dart | 60 ++++++++++++++++++++++++++--------------- lib/pages/settings.dart | 2 +- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 1c1105f..9dbbbf8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -38,10 +38,46 @@ void main() async { //log.i(await api.getMyProfile()); } + class Root extends StatefulWidget { const Root({super.key}); -<<<<<<< HEAD + @override + State createState() => RootState(); +} + +// <<<<<<< HEAD +// @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: LoginPage(), +// ); +// }, +// ); + +// @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 Widget build(BuildContext ctx) { return ValueListenableBuilder( @@ -55,30 +91,10 @@ class Root extends StatefulWidget { darkTheme: ThemeData.dark(), // Here, 'currentTheme' is the local variable provided by the builder themeMode: currentTheme, - home: LoginPage(), + home: auth.hasUser ? App() : LoginPage(), ); }, ); -======= - @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 Widget build(BuildContext ctx) { - if (auth.hasUser) { - return App(); - } else { - return LoginPage(); - } ->>>>>>> 52f4e98cbf55dfa5e4ed32d8d334ed260f8ce8c2 } } diff --git a/lib/pages/settings.dart b/lib/pages/settings.dart index 9bcfab1..81f2363 100644 --- a/lib/pages/settings.dart +++ b/lib/pages/settings.dart @@ -3,7 +3,7 @@ import '../auth.dart'; import '../main.dart'; // Import to access themeModeNotifier import 'package:shared_preferences/shared_preferences.dart'; -class SettingsScreen extends StatelessWidget { +class SettingsPage extends StatelessWidget { @override Widget build(BuildContext context) { From d91c5fda04cbb243fed845a1a546d415bec8d0c8 Mon Sep 17 00:00:00 2001 From: Erik Burgess Date: Mon, 21 Apr 2025 11:16:05 -0700 Subject: [PATCH 3/4] removing commented code --- lib/main.dart | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 9dbbbf8..4ba79d0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -45,29 +45,7 @@ class Root extends StatefulWidget { State createState() => RootState(); } -// <<<<<<< HEAD -// @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: LoginPage(), -// ); -// }, -// ); - -// @override State createState() => RootState(); - -// } class RootState extends State { @override void initState() { From eaef943452e892c961f26cf5084a2038b8567525 Mon Sep 17 00:00:00 2001 From: Erik Burgess Date: Mon, 21 Apr 2025 11:21:44 -0700 Subject: [PATCH 4/4] removing more commented code --- lib/main.dart | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 4ba79d0..1eb45f6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -29,13 +29,8 @@ void main() async { 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()); }