mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 17:29:50 +08:00
Settings: Null safety++
This commit is contained in:
@ -26,7 +26,7 @@ class SortingOrder {
|
|||||||
Descending,
|
Descending,
|
||||||
];
|
];
|
||||||
|
|
||||||
static SortingOrder fromInternalString(String str) {
|
static SortingOrder fromInternalString(String? str) {
|
||||||
for (var opt in options) {
|
for (var opt in options) {
|
||||||
if (opt.toInternalString() == str) {
|
if (opt.toInternalString() == str) {
|
||||||
return opt;
|
return opt;
|
||||||
@ -90,7 +90,7 @@ class SortingField {
|
|||||||
Title,
|
Title,
|
||||||
];
|
];
|
||||||
|
|
||||||
static SortingField fromInternalString(String str) {
|
static SortingField fromInternalString(String? str) {
|
||||||
for (var opt in options) {
|
for (var opt in options) {
|
||||||
if (opt.toInternalString() == str) {
|
if (opt.toInternalString() == str) {
|
||||||
return opt;
|
return opt;
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2020-2021 Vishesh Handa <me@vhanda.in>
|
Copyright 2020-2021 Vishesh Handa <me@vhanda.in>
|
||||||
Roland Fredenhagen <important@van-fredenhagen.de>
|
Roland Fredenhagen <important@van-fredenhagen.de>
|
||||||
@ -235,27 +233,27 @@ class Settings extends ChangeNotifier {
|
|||||||
storageLocation = _getString(pref, "storageLocation") ?? "";
|
storageLocation = _getString(pref, "storageLocation") ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
String _getString(SharedPreferences pref, String key) {
|
String? _getString(SharedPreferences pref, String key) {
|
||||||
return pref.getString(id + '_' + key);
|
return pref.getString(id + '_' + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _getBool(SharedPreferences pref, String key) {
|
bool? _getBool(SharedPreferences pref, String key) {
|
||||||
return pref.getBool(id + '_' + key);
|
return pref.getBool(id + '_' + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> _getStringList(SharedPreferences pref, String key) {
|
List<String>? _getStringList(SharedPreferences pref, String key) {
|
||||||
return pref.getStringList(id + '_' + key);
|
return pref.getStringList(id + '_' + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> _getStringSet(SharedPreferences pref, String key) {
|
Set<String>? _getStringSet(SharedPreferences pref, String key) {
|
||||||
return _getStringList(pref, key)?.toSet();
|
return _getStringList(pref, key)?.toSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
int _getInt(SharedPreferences pref, String key) {
|
int? _getInt(SharedPreferences pref, String key) {
|
||||||
return pref.getInt(id + '_' + key);
|
return pref.getInt(id + '_' + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
double _getDouble(SharedPreferences pref, String key) {
|
double? _getDouble(SharedPreferences pref, String key) {
|
||||||
return pref.getDouble(id + '_' + key);
|
return pref.getDouble(id + '_' + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,7 +408,7 @@ class Settings extends ChangeNotifier {
|
|||||||
SharedPreferences pref,
|
SharedPreferences pref,
|
||||||
String key,
|
String key,
|
||||||
String value,
|
String value,
|
||||||
String defaultValue,
|
String? defaultValue,
|
||||||
) async {
|
) async {
|
||||||
key = id + '_' + key;
|
key = id + '_' + key;
|
||||||
if (value == defaultValue) {
|
if (value == defaultValue) {
|
||||||
@ -470,7 +468,8 @@ class Settings extends ChangeNotifier {
|
|||||||
) async {
|
) async {
|
||||||
key = id + '_' + key;
|
key = id + '_' + key;
|
||||||
|
|
||||||
final eq = const SetEquality().equals;
|
final bool Function(Set<dynamic>, Set<dynamic>) eq =
|
||||||
|
const SetEquality().equals;
|
||||||
|
|
||||||
if (eq(value, defaultValue)) {
|
if (eq(value, defaultValue)) {
|
||||||
await pref.remove(key);
|
await pref.remove(key);
|
||||||
@ -479,8 +478,8 @@ class Settings extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> toMap() {
|
Map<String, String?> toMap() {
|
||||||
return <String, String>{
|
return <String, String?>{
|
||||||
"gitAuthor": gitAuthor,
|
"gitAuthor": gitAuthor,
|
||||||
"gitAuthorEmail": gitAuthorEmail,
|
"gitAuthorEmail": gitAuthorEmail,
|
||||||
"noteFileNameFormat": noteFileNameFormat.toInternalString(),
|
"noteFileNameFormat": noteFileNameFormat.toInternalString(),
|
||||||
@ -544,7 +543,7 @@ class Settings extends ChangeNotifier {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> toLoggableMap() {
|
Map<String, String?> toLoggableMap() {
|
||||||
var m = toMap();
|
var m = toMap();
|
||||||
m.remove("gitAuthor");
|
m.remove("gitAuthor");
|
||||||
m.remove("gitAuthorEmail");
|
m.remove("gitAuthorEmail");
|
||||||
@ -552,7 +551,7 @@ class Settings extends ChangeNotifier {
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> buildRepoPath(String internalDir) async {
|
Future<String?> buildRepoPath(String internalDir) async {
|
||||||
if (storeInternally) {
|
if (storeInternally) {
|
||||||
return p.join(internalDir, folderName);
|
return p.join(internalDir, folderName);
|
||||||
}
|
}
|
||||||
@ -564,6 +563,9 @@ class Settings extends ChangeNotifier {
|
|||||||
// must be called
|
// must be called
|
||||||
//
|
//
|
||||||
var basePath = await ICloudDocumentsPath.documentsPath;
|
var basePath = await ICloudDocumentsPath.documentsPath;
|
||||||
|
if (basePath == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
assert(basePath == storageLocation);
|
assert(basePath == storageLocation);
|
||||||
return p.join(basePath, folderName);
|
return p.join(basePath, folderName);
|
||||||
}
|
}
|
||||||
@ -604,7 +606,7 @@ class NoteFileNameFormat {
|
|||||||
DateOnly,
|
DateOnly,
|
||||||
];
|
];
|
||||||
|
|
||||||
static NoteFileNameFormat fromInternalString(String str) {
|
static NoteFileNameFormat fromInternalString(String? str) {
|
||||||
for (var opt in options) {
|
for (var opt in options) {
|
||||||
if (opt.toInternalString() == str) {
|
if (opt.toInternalString() == str) {
|
||||||
return opt;
|
return opt;
|
||||||
@ -666,7 +668,7 @@ class RemoteSyncFrequency {
|
|||||||
Manual,
|
Manual,
|
||||||
];
|
];
|
||||||
|
|
||||||
static RemoteSyncFrequency fromInternalString(String str) {
|
static RemoteSyncFrequency fromInternalString(String? str) {
|
||||||
for (var opt in options) {
|
for (var opt in options) {
|
||||||
if (opt.toInternalString() == str) {
|
if (opt.toInternalString() == str) {
|
||||||
return opt;
|
return opt;
|
||||||
@ -742,7 +744,6 @@ class SettingsEditorType {
|
|||||||
case EditorType.Org:
|
case EditorType.Org:
|
||||||
return SettingsEditorType.Org;
|
return SettingsEditorType.Org;
|
||||||
}
|
}
|
||||||
return SettingsEditorType.Default;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const options = <SettingsEditorType>[
|
static const options = <SettingsEditorType>[
|
||||||
@ -752,7 +753,7 @@ class SettingsEditorType {
|
|||||||
Checklist,
|
Checklist,
|
||||||
];
|
];
|
||||||
|
|
||||||
static SettingsEditorType fromInternalString(String str) {
|
static SettingsEditorType fromInternalString(String? str) {
|
||||||
for (var opt in options) {
|
for (var opt in options) {
|
||||||
if (opt.toInternalString() == str) {
|
if (opt.toInternalString() == str) {
|
||||||
return opt;
|
return opt;
|
||||||
@ -807,7 +808,7 @@ class SettingsFolderViewType {
|
|||||||
Grid,
|
Grid,
|
||||||
];
|
];
|
||||||
|
|
||||||
static SettingsFolderViewType fromInternalString(String str) {
|
static SettingsFolderViewType fromInternalString(String? str) {
|
||||||
for (var opt in options) {
|
for (var opt in options) {
|
||||||
if (opt.toInternalString() == str) {
|
if (opt.toInternalString() == str) {
|
||||||
return opt;
|
return opt;
|
||||||
@ -857,7 +858,6 @@ class SettingsFolderViewType {
|
|||||||
case FolderViewType.Grid:
|
case FolderViewType.Grid:
|
||||||
return SettingsFolderViewType.Grid;
|
return SettingsFolderViewType.Grid;
|
||||||
}
|
}
|
||||||
return SettingsFolderViewType.Default;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -888,7 +888,7 @@ class SettingsMarkdownDefaultView {
|
|||||||
LastUsed,
|
LastUsed,
|
||||||
];
|
];
|
||||||
|
|
||||||
static SettingsMarkdownDefaultView fromInternalString(String str) {
|
static SettingsMarkdownDefaultView fromInternalString(String? str) {
|
||||||
for (var opt in options) {
|
for (var opt in options) {
|
||||||
if (opt.toInternalString() == str) {
|
if (opt.toInternalString() == str) {
|
||||||
return opt;
|
return opt;
|
||||||
@ -938,7 +938,7 @@ class SettingsHomeScreen {
|
|||||||
AllFolders,
|
AllFolders,
|
||||||
];
|
];
|
||||||
|
|
||||||
static SettingsHomeScreen fromInternalString(String str) {
|
static SettingsHomeScreen fromInternalString(String? str) {
|
||||||
for (var opt in options) {
|
for (var opt in options) {
|
||||||
if (opt.toInternalString() == str) {
|
if (opt.toInternalString() == str) {
|
||||||
return opt;
|
return opt;
|
||||||
@ -993,7 +993,7 @@ class SettingsImageTextType {
|
|||||||
None,
|
None,
|
||||||
];
|
];
|
||||||
|
|
||||||
static SettingsImageTextType fromInternalString(String str) {
|
static SettingsImageTextType fromInternalString(String? str) {
|
||||||
for (var opt in options) {
|
for (var opt in options) {
|
||||||
if (opt.toInternalString() == str) {
|
if (opt.toInternalString() == str) {
|
||||||
return opt;
|
return opt;
|
||||||
@ -1046,7 +1046,7 @@ class SettingsThemeVectorGraphics {
|
|||||||
Filter,
|
Filter,
|
||||||
];
|
];
|
||||||
|
|
||||||
static SettingsThemeVectorGraphics fromInternalString(String str) {
|
static SettingsThemeVectorGraphics fromInternalString(String? str) {
|
||||||
for (var opt in options) {
|
for (var opt in options) {
|
||||||
if (opt.toInternalString() == str) {
|
if (opt.toInternalString() == str) {
|
||||||
return opt;
|
return opt;
|
||||||
@ -1100,7 +1100,7 @@ class SettingsVectorGraphicsAdjustColors {
|
|||||||
All,
|
All,
|
||||||
];
|
];
|
||||||
|
|
||||||
static SettingsVectorGraphicsAdjustColors fromInternalString(String str) {
|
static SettingsVectorGraphicsAdjustColors fromInternalString(String? str) {
|
||||||
for (var opt in options) {
|
for (var opt in options) {
|
||||||
if (opt.toInternalString() == str) {
|
if (opt.toInternalString() == str) {
|
||||||
return opt;
|
return opt;
|
||||||
@ -1155,7 +1155,7 @@ class SettingsTheme {
|
|||||||
SystemDefault,
|
SystemDefault,
|
||||||
];
|
];
|
||||||
|
|
||||||
static SettingsTheme fromInternalString(String str) {
|
static SettingsTheme fromInternalString(String? str) {
|
||||||
for (var opt in options) {
|
for (var opt in options) {
|
||||||
if (opt.toInternalString() == str) {
|
if (opt.toInternalString() == str) {
|
||||||
return opt;
|
return opt;
|
||||||
@ -1218,7 +1218,7 @@ class SettingsTitle {
|
|||||||
// InFileName,
|
// InFileName,
|
||||||
];
|
];
|
||||||
|
|
||||||
static SettingsTitle fromInternalString(String str) {
|
static SettingsTitle fromInternalString(String? str) {
|
||||||
for (var opt in options) {
|
for (var opt in options) {
|
||||||
if (opt.toInternalString() == str) {
|
if (opt.toInternalString() == str) {
|
||||||
return opt;
|
return opt;
|
||||||
|
Reference in New Issue
Block a user