mirror of
https://github.com/git-touch/git-touch
synced 2024-12-18 19:22:54 +01:00
refactor: storage keys
This commit is contained in:
parent
fccb79b2cc
commit
e1e421542b
@ -5,11 +5,6 @@ import 'package:git_touch/utils/utils.dart';
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class CodeModel with ChangeNotifier {
|
class CodeModel with ChangeNotifier {
|
||||||
static const _kTheme = 'code-theme';
|
|
||||||
static const _kThemeDark = 'code-theme-dark';
|
|
||||||
static const _kFontSize = 'code-font-size';
|
|
||||||
static const _kFontFamily = 'code-font-family';
|
|
||||||
|
|
||||||
static var themes = themeMap.keys.toList();
|
static var themes = themeMap.keys.toList();
|
||||||
static const fontSizes = [12, 13, 14, 15, 16, 17, 18, 19, 20];
|
static const fontSizes = [12, 13, 14, 15, 16, 17, 18, 19, 20];
|
||||||
static const fontFamilies = [
|
static const fontFamilies = [
|
||||||
@ -35,10 +30,10 @@ class CodeModel with ChangeNotifier {
|
|||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
var prefs = await SharedPreferences.getInstance();
|
var prefs = await SharedPreferences.getInstance();
|
||||||
var vh = prefs.getString(_kTheme);
|
var vh = prefs.getString(StorageKeys.codeTheme);
|
||||||
var vdh = prefs.getString(_kThemeDark);
|
var vdh = prefs.getString(StorageKeys.codeThemeDark);
|
||||||
var vs = prefs.getInt(_kFontSize);
|
var vs = prefs.getInt(StorageKeys.iCodeFontSize);
|
||||||
var vf = prefs.getString(_kFontFamily);
|
var vf = prefs.getString(StorageKeys.codeFontFamily);
|
||||||
|
|
||||||
Fimber.d('read code: $vh, $vs, $vf');
|
Fimber.d('read code: $vh, $vs, $vf');
|
||||||
if (themeMap.keys.contains(vh)) {
|
if (themeMap.keys.contains(vh)) {
|
||||||
@ -60,7 +55,7 @@ class CodeModel with ChangeNotifier {
|
|||||||
setTheme(String v) async {
|
setTheme(String v) async {
|
||||||
var prefs = await SharedPreferences.getInstance();
|
var prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
await prefs.setString(_kTheme, v);
|
await prefs.setString(StorageKeys.codeTheme, v);
|
||||||
Fimber.d('write code theme: $v');
|
Fimber.d('write code theme: $v');
|
||||||
|
|
||||||
_theme = v;
|
_theme = v;
|
||||||
@ -70,7 +65,7 @@ class CodeModel with ChangeNotifier {
|
|||||||
setThemeDark(String v) async {
|
setThemeDark(String v) async {
|
||||||
var prefs = await SharedPreferences.getInstance();
|
var prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
await prefs.setString(_kThemeDark, v);
|
await prefs.setString(StorageKeys.codeThemeDark, v);
|
||||||
Fimber.d('write code theme dark: $v');
|
Fimber.d('write code theme dark: $v');
|
||||||
|
|
||||||
_themeDark = v;
|
_themeDark = v;
|
||||||
@ -80,7 +75,7 @@ class CodeModel with ChangeNotifier {
|
|||||||
setFontSize(int v) async {
|
setFontSize(int v) async {
|
||||||
var prefs = await SharedPreferences.getInstance();
|
var prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
await prefs.setInt(_kFontSize, v);
|
await prefs.setInt(StorageKeys.iCodeFontSize, v);
|
||||||
Fimber.d('write code font size: $v');
|
Fimber.d('write code font size: $v');
|
||||||
|
|
||||||
_fontSize = v;
|
_fontSize = v;
|
||||||
@ -90,7 +85,7 @@ class CodeModel with ChangeNotifier {
|
|||||||
setFontFamily(String v) async {
|
setFontFamily(String v) async {
|
||||||
var prefs = await SharedPreferences.getInstance();
|
var prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
await prefs.setString(_kFontFamily, v);
|
await prefs.setString(StorageKeys.codeFontFamily, v);
|
||||||
Fimber.d('write code font family: $v');
|
Fimber.d('write code font family: $v');
|
||||||
|
|
||||||
_fontFamily = v;
|
_fontFamily = v;
|
||||||
|
@ -97,8 +97,6 @@ class Palette {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ThemeModel with ChangeNotifier {
|
class ThemeModel with ChangeNotifier {
|
||||||
static const kBrightness = 'brightness';
|
|
||||||
|
|
||||||
int _theme;
|
int _theme;
|
||||||
int get theme => _theme;
|
int get theme => _theme;
|
||||||
bool get ready => _theme != null;
|
bool get ready => _theme != null;
|
||||||
@ -132,7 +130,7 @@ class ThemeModel with ChangeNotifier {
|
|||||||
Future<void> setBrightness(int v) async {
|
Future<void> setBrightness(int v) async {
|
||||||
_brightnessValue = v;
|
_brightnessValue = v;
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
await prefs.setInt(kBrightness, v);
|
await prefs.setInt(StorageKeys.iBrightness, v);
|
||||||
Fimber.d('write brightness: $v');
|
Fimber.d('write brightness: $v');
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
@ -171,7 +169,7 @@ class ThemeModel with ChangeNotifier {
|
|||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
final v = prefs.getInt(StorageKeys.theme);
|
final v = prefs.getInt(StorageKeys.iTheme);
|
||||||
Fimber.d('read theme: $v');
|
Fimber.d('read theme: $v');
|
||||||
if (AppThemeType.values.contains(v)) {
|
if (AppThemeType.values.contains(v)) {
|
||||||
_theme = v;
|
_theme = v;
|
||||||
@ -180,7 +178,7 @@ class ThemeModel with ChangeNotifier {
|
|||||||
} else {
|
} else {
|
||||||
_theme = AppThemeType.material;
|
_theme = AppThemeType.material;
|
||||||
}
|
}
|
||||||
final b = prefs.getInt(kBrightness);
|
final b = prefs.getInt(StorageKeys.iBrightness);
|
||||||
Fimber.d('read brightness: $b');
|
Fimber.d('read brightness: $b');
|
||||||
if (AppBrightnessType.values.contains(b)) {
|
if (AppBrightnessType.values.contains(b)) {
|
||||||
_brightnessValue = b;
|
_brightnessValue = b;
|
||||||
@ -192,7 +190,7 @@ class ThemeModel with ChangeNotifier {
|
|||||||
Future<void> setTheme(int v) async {
|
Future<void> setTheme(int v) async {
|
||||||
_theme = v;
|
_theme = v;
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
await prefs.setInt(StorageKeys.theme, v);
|
await prefs.setInt(StorageKeys.iTheme, v);
|
||||||
Fimber.d('write theme: $v');
|
Fimber.d('write theme: $v');
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import 'package:provider/provider.dart';
|
|||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
export 'extensions.dart';
|
export 'extensions.dart';
|
||||||
|
|
||||||
export 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
export 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
||||||
|
|
||||||
class StorageKeys {
|
class StorageKeys {
|
||||||
@ -21,7 +20,12 @@ class StorageKeys {
|
|||||||
static const github = 'github';
|
static const github = 'github';
|
||||||
|
|
||||||
static const accounts = 'accounts';
|
static const accounts = 'accounts';
|
||||||
static const theme = 'theme';
|
static const iTheme = 'theme';
|
||||||
|
static const iBrightness = 'brightness';
|
||||||
|
static const codeTheme = 'code-theme';
|
||||||
|
static const codeThemeDark = 'code-theme-dark';
|
||||||
|
static const iCodeFontSize = 'code-font-size';
|
||||||
|
static const codeFontFamily = 'code-font-family';
|
||||||
}
|
}
|
||||||
|
|
||||||
class CommonStyle {
|
class CommonStyle {
|
||||||
|
Loading…
Reference in New Issue
Block a user