Skip to content

Commit ea12fe4

Browse files
committed
✨ ui: Not working theme switcher
Changelog: ui
1 parent a70a758 commit ea12fe4

2 files changed

Lines changed: 111 additions & 1 deletion

File tree

lib/screens/profile_screen.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:supabase_auth_ui/supabase_auth_ui.dart';
3-
import '../main.dart'; // Add this import for MyHomePage
3+
import '../main.dart';
4+
import 'settings_screen.dart';
45

56
class ProfileScreen extends StatelessWidget {
67
final String email;
@@ -18,6 +19,18 @@ class ProfileScreen extends StatelessWidget {
1819
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
1920
title: const Text('Profile'),
2021
actions: [
22+
// Settings button
23+
IconButton(
24+
icon: const Icon(Icons.settings),
25+
onPressed: () {
26+
Navigator.of(context).push(
27+
MaterialPageRoute(
28+
builder: (context) => const SettingsScreen(),
29+
),
30+
);
31+
},
32+
),
33+
// Logout button
2134
IconButton(
2235
icon: const Icon(Icons.logout),
2336
onPressed: () async {

lib/screens/settings_screen.dart

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:shared_preferences/shared_preferences.dart';
3+
4+
class SettingsScreen extends StatefulWidget {
5+
const SettingsScreen({super.key});
6+
7+
@override
8+
State<SettingsScreen> createState() => _SettingsScreenState();
9+
}
10+
11+
class _SettingsScreenState extends State<SettingsScreen> {
12+
bool _isDarkMode = false;
13+
final String _themePrefKey = 'isDarkMode';
14+
15+
@override
16+
void initState() {
17+
super.initState();
18+
_loadThemePreference();
19+
}
20+
21+
// Load the theme preference from shared preferences
22+
Future<void> _loadThemePreference() async {
23+
final prefs = await SharedPreferences.getInstance();
24+
setState(() {
25+
_isDarkMode = prefs.getBool(_themePrefKey) ??
26+
MediaQuery.platformBrightnessOf(context) == Brightness.dark;
27+
});
28+
}
29+
30+
// Save the theme preference to shared preferences
31+
Future<void> _saveThemePreference(bool isDark) async {
32+
final prefs = await SharedPreferences.getInstance();
33+
await prefs.setBool(_themePrefKey, isDark);
34+
}
35+
36+
@override
37+
Widget build(BuildContext context) {
38+
return Scaffold(
39+
appBar: AppBar(
40+
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
41+
title: const Text('Settings'),
42+
),
43+
body: Padding(
44+
padding: const EdgeInsets.all(16.0),
45+
child: Column(
46+
crossAxisAlignment: CrossAxisAlignment.start,
47+
children: [
48+
Text(
49+
'Appearance',
50+
style: Theme.of(context).textTheme.titleLarge,
51+
),
52+
const SizedBox(height: 16),
53+
SwitchListTile(
54+
title: const Text('Dark Mode'),
55+
subtitle: const Text('Toggle between light and dark theme'),
56+
value: _isDarkMode,
57+
onChanged: (bool value) {
58+
setState(() {
59+
_isDarkMode = value;
60+
});
61+
_saveThemePreference(value);
62+
63+
// Show a dialog that requires app restart to apply theme changes
64+
showDialog(
65+
context: context,
66+
builder: (BuildContext context) {
67+
return AlertDialog(
68+
title: const Text('Theme Changed'),
69+
content: const Text(
70+
'The app needs to restart to apply theme changes. Please restart the app.',
71+
),
72+
actions: [
73+
TextButton(
74+
onPressed: () {
75+
Navigator.of(context).pop();
76+
},
77+
child: const Text('OK'),
78+
),
79+
],
80+
);
81+
},
82+
);
83+
},
84+
),
85+
const Divider(),
86+
const SizedBox(height: 16),
87+
Text(
88+
'Other Settings',
89+
style: Theme.of(context).textTheme.titleLarge,
90+
),
91+
// Add more settings options here
92+
],
93+
),
94+
),
95+
);
96+
}
97+
}

0 commit comments

Comments
 (0)