diff options
author | Iván Ávalos <avalos@disroot.org> | 2023-05-27 13:14:45 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2023-05-27 13:25:24 -0600 |
commit | a88ccf31b59541faea8c38c638737c1359cfff47 (patch) | |
tree | 30acf22e4df0bfa41b34e40b223521fbef5a4730 /lib/settings | |
parent | d0d54a9d6e7ac947ae86962b6bbc7eeb9ada5011 (diff) | |
download | linkchat-a88ccf31b59541faea8c38c638737c1359cfff47.tar.gz linkchat-a88ccf31b59541faea8c38c638737c1359cfff47.tar.bz2 linkchat-a88ccf31b59541faea8c38c638737c1359cfff47.zip |
Se implementan colores dinámicos (Android 13)
Diffstat (limited to 'lib/settings')
-rw-r--r-- | lib/settings/preferences.dart | 15 | ||||
-rw-r--r-- | lib/settings/themes.dart | 28 |
2 files changed, 22 insertions, 21 deletions
diff --git a/lib/settings/preferences.dart b/lib/settings/preferences.dart index 3c0ef5d..9cfbf6a 100644 --- a/lib/settings/preferences.dart +++ b/lib/settings/preferences.dart @@ -1,4 +1,3 @@ -import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../settings/themes.dart'; @@ -11,21 +10,21 @@ class Preferences { return _prefs!; } - static Future<ThemeData?> getTheme() async { + static Future<ThemeEnum> getTheme() async { switch ((await prefs).getString('theme')) { case 'light': - return ThemeSettings.lightTheme; + return ThemeEnum.light; case 'dark': - return ThemeSettings.darkTheme; + return ThemeEnum.dark; } - return null; + return ThemeEnum.auto; } - static void setTheme(ThemeData? theme) { + static void setTheme(ThemeEnum? theme) { prefs.then((p) { - if (theme == ThemeSettings.lightTheme) { + if (theme == ThemeEnum.light) { p.setString('theme', 'light'); - } else if (theme == ThemeSettings.darkTheme) { + } else if (theme == ThemeEnum.dark) { p.setString('theme', 'dark'); } else { p.remove('theme'); diff --git a/lib/settings/themes.dart b/lib/settings/themes.dart index cc506a9..b9a09d7 100644 --- a/lib/settings/themes.dart +++ b/lib/settings/themes.dart @@ -1,18 +1,20 @@ import 'package:flutter/material.dart'; +enum ThemeEnum { light, dark, auto } + class ThemeSettings { - static ThemeData lightTheme = ThemeData( - useMaterial3: true, - primaryColor: Colors.purple, - fontFamily: 'Manrope', - ); + static ThemeData lightTheme(ColorScheme? lightDynamic) => ThemeData( + useMaterial3: true, + primaryColor: Colors.purple, + fontFamily: 'Manrope', + colorScheme: lightDynamic, + ); - static ThemeData darkTheme = ThemeData( - useMaterial3: true, - brightness: Brightness.dark, - fontFamily: 'Manrope', - colorScheme: const ColorScheme.dark().copyWith( - primary: Colors.purple, - ), - ); + static ThemeData darkTheme(ColorScheme? darkDynamic) => ThemeData( + useMaterial3: true, + brightness: Brightness.dark, + fontFamily: 'Manrope', + primaryColor: Colors.purple, + colorScheme: (darkDynamic ?? const ColorScheme.dark()), + ); } |