Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 41 additions & 20 deletions lib/main.dart
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should remove unnecessary comments when merging, especially previous code because those will be in the git commit history

Original file line number Diff line number Diff line change
Expand Up @@ -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<ThemeMode> 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<Root> createState() => RootState();
@override
State<Root> createState() => RootState();
}


class RootState extends State<Root> {
@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<ThemeMode>(
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(),
);
},
);
}
}

Expand Down
124 changes: 106 additions & 18 deletions lib/pages/settings.dart
Original file line number Diff line number Diff line change
@@ -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<ThemeMode>(
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.
),
),
),
)
],
),
),
),
);
}
}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading