forked from thunder-app/thunder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved theming options to separate section
- Loading branch information
Showing
5 changed files
with
128 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
import 'package:thunder/core/theme/bloc/theme_bloc.dart'; | ||
import 'package:thunder/settings/widgets/toggle_option.dart'; | ||
import 'package:thunder/thunder/bloc/thunder_bloc.dart'; | ||
|
||
class ThemeSettingsPage extends StatefulWidget { | ||
const ThemeSettingsPage({super.key}); | ||
|
||
@override | ||
State<ThemeSettingsPage> createState() => _ThemeSettingsPageState(); | ||
} | ||
|
||
class _ThemeSettingsPageState extends State<ThemeSettingsPage> { | ||
String themeType = 'dark'; | ||
bool useBlackTheme = false; | ||
|
||
// Loading | ||
bool isLoading = true; | ||
|
||
void setPreferences(attribute, value) async { | ||
final prefs = await SharedPreferences.getInstance(); | ||
|
||
switch (attribute) { | ||
case 'setting_theme_type': | ||
await prefs.setString('setting_theme_type', value); | ||
setState(() => themeType = value); | ||
if (context.mounted) context.read<ThemeBloc>().add(ThemeChangeEvent()); | ||
break; | ||
case 'setting_theme_use_black_theme': | ||
await prefs.setBool('setting_theme_use_black_theme', value); | ||
setState(() => useBlackTheme = value); | ||
if (context.mounted) context.read<ThemeBloc>().add(ThemeChangeEvent()); | ||
break; | ||
} | ||
|
||
if (context.mounted) { | ||
context.read<ThunderBloc>().add(UserPreferencesChangeEvent()); | ||
} | ||
} | ||
|
||
void _initPreferences() async { | ||
final prefs = await SharedPreferences.getInstance(); | ||
|
||
setState(() { | ||
// Theme Settings | ||
themeType = prefs.getString('setting_theme_type') ?? 'dark'; | ||
useBlackTheme = prefs.getBool('setting_theme_use_black_theme') ?? false; | ||
|
||
isLoading = false; | ||
}); | ||
} | ||
|
||
@override | ||
void initState() { | ||
WidgetsBinding.instance.addPostFrameCallback((_) => _initPreferences()); | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final ThemeData theme = Theme.of(context); | ||
|
||
return Scaffold( | ||
appBar: AppBar(title: const Text('Theming'), centerTitle: false), | ||
body: isLoading | ||
? const Center(child: CircularProgressIndicator()) | ||
: SingleChildScrollView( | ||
child: Column( | ||
children: [ | ||
Container( | ||
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0), | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.start, | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.only(bottom: 8.0), | ||
child: Text( | ||
'Theme', | ||
style: theme.textTheme.titleLarge, | ||
), | ||
), | ||
ToggleOption( | ||
description: 'Use dark theme', | ||
value: themeType == 'dark', | ||
iconEnabled: Icons.dark_mode_rounded, | ||
iconDisabled: Icons.dark_mode_outlined, | ||
onToggle: (bool value) => setPreferences('setting_theme_type', value == true ? 'dark' : 'light'), | ||
), | ||
ToggleOption( | ||
description: 'Pure black theme', | ||
value: useBlackTheme, | ||
iconEnabled: Icons.dark_mode_outlined, | ||
iconDisabled: Icons.dark_mode_outlined, | ||
onToggle: (bool value) => setPreferences('setting_theme_use_black_theme', value), | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |