-
Notifications
You must be signed in to change notification settings - Fork 156
Theme change functionality #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AliAkberAakash
wants to merge
8
commits into
hasancse91:master
Choose a base branch
from
AliAkberAakash:theme-change-functionality
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c855872
add theme change functionality on settings page
AliAkberAakash a1888c9
reformatted code
AliAkberAakash 50e6208
Merge branch 'master' into theme-change-functionality
AliAkberAakash 5d8e25d
Merge branch 'hasancse91:master' into theme-change-functionality
AliAkberAakash 6c415c1
merge: merged from master
AliAkberAakash 6ff460a
add theme choosing dialog
AliAkberAakash 8f271bb
change code structure
AliAkberAakash 9ad691f
fixed error on bn file
AliAkberAakash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,45 @@ | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| import 'app_colors.dart'; | ||
|
|
||
| class AppThemes { | ||
| // light theme configurations | ||
| static ThemeData get lightTheme { | ||
| return ThemeData( | ||
| primarySwatch: AppColors.colorPrimarySwatch, | ||
| visualDensity: VisualDensity.adaptivePlatformDensity, | ||
| brightness: Brightness.light, | ||
| primaryColor: AppColors.colorPrimary, | ||
| canvasColor: AppColors.canvasColor, | ||
| cardColor: AppColors.canvasColor, | ||
| textTheme: const TextTheme( | ||
| button: TextStyle( | ||
| color: Colors.white, | ||
| fontSize: 20.0, | ||
| fontWeight: FontWeight.bold, | ||
| ), | ||
| ), | ||
| fontFamily: 'Roboto', | ||
| ); | ||
| } | ||
|
|
||
| // dark theme configurations | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our code should be self explanatory. don't need to add unnecessary comment. |
||
| static ThemeData get darkTheme { | ||
| return ThemeData( | ||
| primarySwatch: AppColors.colorPrimarySwatch, | ||
| visualDensity: VisualDensity.adaptivePlatformDensity, | ||
| brightness: Brightness.dark, | ||
| primaryColor: AppColors.colorPrimary, | ||
| canvasColor: AppColors.canvasColorDark, | ||
| cardColor: AppColors.canvasColorDark, | ||
| textTheme: const TextTheme( | ||
| button: TextStyle( | ||
| color: Colors.white, | ||
| fontSize: 20.0, | ||
| fontWeight: FontWeight.bold, | ||
| ), | ||
| ), | ||
| fontFamily: 'Roboto', | ||
| ); | ||
| } | ||
| } | ||
10 changes: 6 additions & 4 deletions
10
lib/app/modules/settings/controllers/settings_controller.dart
This file contains hidden or 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 |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
|
|
||
| import 'package:flutter_getx_template/app/core/base/base_controller.dart'; | ||
| import 'package:flutter_getx_template/app/modules/theme/theme_controller.dart'; | ||
| import 'package:get/get.dart'; | ||
| import '../../theme/theme_controller.dart'; | ||
|
|
||
| import '/app/core/base/base_controller.dart'; | ||
| class SettingsController extends BaseController{ | ||
|
|
||
| class SettingsController extends BaseController { | ||
| final count = 0.obs; | ||
| ThemeController themeController = Get.find<ThemeController>(); | ||
|
|
||
| void increment() => count.value++; | ||
| } |
70 changes: 70 additions & 0 deletions
70
lib/app/modules/settings/dialogs/theme_changing_dialog.dart
This file contains hidden or 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,70 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:get/get.dart'; | ||
|
|
||
| import '../../../core/base/base_widget_mixin.dart'; | ||
| import '../../theme/theme_controller.dart'; | ||
| import '../controllers/settings_controller.dart'; | ||
|
|
||
| // ignore: must_be_immutable | ||
| class ThemeChangingDialog extends StatelessWidget with BaseWidgetMixin { | ||
| final SettingsController controller; | ||
| final ThemeController _themeController; | ||
|
|
||
| ThemeChangingDialog({Key? key, required this.controller}) | ||
| : _themeController = controller.themeController, | ||
| super(key: key); | ||
|
|
||
| ThemeMode? _selectedMode; | ||
|
|
||
| @override | ||
| Widget body(BuildContext context) { | ||
| return Obx(() { | ||
| _selectedMode = _themeController.currentThemeMode.value; | ||
|
|
||
| return _selectedMode == null ? _loadingWidget() : _bodyWidget(context); | ||
| }); | ||
| } | ||
|
|
||
| Widget _loadingWidget() { | ||
| return Center( | ||
| child: CircularProgressIndicator( | ||
| color: appTheme.primaryColor, | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| Widget _bodyWidget(BuildContext context) { | ||
| return Column( | ||
| mainAxisSize: MainAxisSize.min, | ||
| children: [ | ||
| RadioListTile( | ||
| value: ThemeMode.light, | ||
| groupValue: _selectedMode, | ||
| onChanged: (_) { | ||
| _themeController.setLightThemeMode(); | ||
| Navigator.pop(context); | ||
| }, | ||
| title: Text(appLocalization.lightTheme), | ||
| ), | ||
| RadioListTile( | ||
| value: ThemeMode.dark, | ||
| groupValue: _selectedMode, | ||
| onChanged: (_) { | ||
| _themeController.setDarkThemeMode(); | ||
| Navigator.pop(context); | ||
| }, | ||
| title: Text(appLocalization.darkTheme), | ||
| ), | ||
| RadioListTile( | ||
| value: ThemeMode.system, | ||
| groupValue: _selectedMode, | ||
| onChanged: (_) { | ||
| _themeController.setSystemThemeMode(); | ||
| Navigator.pop(context); | ||
| }, | ||
| title: Text(appLocalization.systemDefault), | ||
| ), | ||
| ], | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,33 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:get/get.dart'; | ||
|
|
||
| import '../../core/base/base_controller.dart'; | ||
| import 'theme_service.dart'; | ||
|
|
||
| class ThemeController extends BaseController { | ||
| final ThemeService themeService = ThemeService(); | ||
| final Rx<ThemeMode> currentThemeMode = Rx<ThemeMode>(ThemeMode.system); | ||
|
|
||
| ThemeController() { | ||
| getCurrentThemeMode(); | ||
| } | ||
|
|
||
| void getCurrentThemeMode() async { | ||
| currentThemeMode.value = await themeService.themeMode; | ||
| } | ||
|
|
||
| void setDarkThemeMode() async { | ||
| await themeService.setDarkMode(); | ||
| getCurrentThemeMode(); | ||
| } | ||
|
|
||
| void setLightThemeMode() async { | ||
| await themeService.setLightMode(); | ||
| getCurrentThemeMode(); | ||
| } | ||
|
|
||
| void setSystemThemeMode() async { | ||
| await themeService.setSystemMode(); | ||
| getCurrentThemeMode(); | ||
| } | ||
| } |
This file contains hidden or 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,44 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:get/get.dart'; | ||
|
|
||
| import '../../data/local/preference/preference_manager.dart'; | ||
|
|
||
| const String DARK_THEME = "dark_theme"; | ||
| const String LIGHT_THEME = "light_theme"; | ||
| const String SYSTEM_THEME = "system_theme"; | ||
|
|
||
| const Map<String, ThemeMode> themeModesMap = { | ||
| DARK_THEME: ThemeMode.dark, | ||
| LIGHT_THEME: ThemeMode.light, | ||
| SYSTEM_THEME: ThemeMode.system, | ||
| }; | ||
|
|
||
| class ThemeService { | ||
| static const THEME_MODE_KEY = 'themeMode'; | ||
|
|
||
| final PreferenceManager _preferenceManager = | ||
| Get.find(tag: (PreferenceManager).toString()); | ||
|
|
||
| Future<ThemeMode> get themeMode async => await _loadThemeFromSharedPref(); | ||
|
|
||
| Future<ThemeMode> _loadThemeFromSharedPref() async { | ||
| final String savedThemeMode = | ||
| await _preferenceManager.getString(THEME_MODE_KEY); | ||
|
|
||
| if (savedThemeMode.isEmpty) return ThemeMode.system; | ||
|
|
||
| return themeModesMap[savedThemeMode]!; | ||
| } | ||
|
|
||
| setDarkMode() async { | ||
| await _preferenceManager.setString(THEME_MODE_KEY, DARK_THEME); | ||
| } | ||
|
|
||
| setLightMode() async { | ||
| await _preferenceManager.setString(THEME_MODE_KEY, LIGHT_THEME); | ||
| } | ||
|
|
||
| setSystemMode() async { | ||
| await _preferenceManager.setString(THEME_MODE_KEY, SYSTEM_THEME); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our code should be self explanatory. don't need to add unnecessary comment.