This commit is contained in:
2021-01-23 19:28:26 -05:00
parent fec7db1890
commit 4378a2927b
51 changed files with 992 additions and 245 deletions

View File

@@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
class AppThemes {
static final appThemeData = {
AppTheme.lightTheme: ThemeData(
scaffoldBackgroundColor: Colors.white,
primarySwatch: Colors.blue,
backgroundColor: Colors.white,
textTheme: TextTheme(
bodyText1: TextStyle(
color: Colors.black,
),
),
),
AppTheme.darkTheme: ThemeData(
scaffoldBackgroundColor: Colors.black,
primarySwatch: Colors.teal,
backgroundColor: Colors.black,
textTheme: TextTheme(
bodyText1: TextStyle(
color: Colors.white,
),
),
)
};
}
enum AppTheme {
lightTheme,
darkTheme,
}

View File

@@ -0,0 +1,39 @@
import 'dart:convert';
import 'package:imagini/settings/app_themes.dart';
import 'package:shared_preferences/shared_preferences.dart';
class Preferences {
//
static SharedPreferences preferences;
static const String KEY_SELECTED_THEME = 'key_selected_theme';
static init() async {
preferences = await SharedPreferences.getInstance();
}
static void saveTheme(AppTheme selectedTheme) async {
if (null == selectedTheme) {
selectedTheme = AppTheme.lightTheme;
}
String theme = jsonEncode(selectedTheme.toString());
preferences.setString(KEY_SELECTED_THEME, theme);
}
static AppTheme getTheme() {
String theme = preferences.getString(KEY_SELECTED_THEME);
if (null == theme) {
return AppTheme.lightTheme;
}
return getThemeFromString(jsonDecode(theme));
}
static AppTheme getThemeFromString(String themeString) {
for (AppTheme theme in AppTheme.values) {
if (theme.toString() == themeString) {
return theme;
}
}
return null;
}
}