Preclean
This commit is contained in:
31
web_native/lib/settings/app_themes.dart
Normal file
31
web_native/lib/settings/app_themes.dart
Normal 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,
|
||||
}
|
||||
39
web_native/lib/settings/preferences.dart
Normal file
39
web_native/lib/settings/preferences.dart
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user