Skip to content

Commit

Permalink
Fix issues with themes
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k committed Jun 19, 2024
1 parent b9f83c4 commit 062ece7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:smooth_app/data_models/product_preferences.dart';
import 'package:smooth_app/pages/onboarding/onboarding_flow_navigator.dart';
import 'package:smooth_app/pages/preferences/user_preferences_dev_mode.dart';
import 'package:smooth_app/themes/color_schemes.dart';
import 'package:smooth_app/themes/theme_provider.dart';

part 'package:smooth_app/data_models/preferences/migration/user_preferences_migration.dart';

Expand Down Expand Up @@ -203,7 +204,8 @@ class UserPreferences extends ChangeNotifier {
_sharedPreferences.getBool(_TAG_CRASH_REPORTS) ?? false;

String get currentTheme =>
_sharedPreferences.getString(_TAG_CURRENT_THEME_MODE) ?? 'System Default';
_sharedPreferences.getString(_TAG_CURRENT_THEME_MODE) ??
THEME_SYSTEM_DEFAULT;

String get currentColor =>
_sharedPreferences.getString(_TAG_CURRENT_COLOR_SCHEME) ??
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/resources/app_animations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class _SearchEyeAnimationState extends State<SearchEyeAnimation> {
@override
Widget build(BuildContext context) {
final double size = widget.size ?? IconTheme.of(context).size ?? 24.0;
final bool lightTheme = context.watch<ThemeProvider>().isDarkMode(context);
final bool lightTheme = !context.watch<ThemeProvider>().isDarkMode(context);

return ExcludeSemantics(
child: SizedBox(
Expand Down
9 changes: 6 additions & 3 deletions packages/smooth_app/lib/themes/theme_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ class ThemeProvider with ChangeNotifier {

Future<void> setTheme(String value) async {
assert(
value != THEME_LIGHT || value != THEME_DARK || value != THEME_AMOLED);
value != THEME_LIGHT || value != THEME_DARK || value != THEME_AMOLED);
await _userPreferences.setTheme(value);
notifyListeners();
}

bool isDarkMode(BuildContext context) {
return currentThemeMode != ThemeMode.light &&
MediaQuery.platformBrightnessOf(context) == Brightness.dark;

if (currentTheme == THEME_SYSTEM_DEFAULT) {
return MediaQuery.platformBrightnessOf(context) == Brightness.dark;
}
return <String>[THEME_DARK, THEME_AMOLED].contains(currentTheme);
}

@override
Expand Down

0 comments on commit 062ece7

Please sign in to comment.