💄 Customizable dashboard

This commit is contained in:
2026-01-17 15:32:08 +08:00
parent c5d667ecf3
commit 6a0f351114
8 changed files with 849 additions and 101 deletions

View File

@@ -42,6 +42,7 @@ const kAppAskedReview = 'app_asked_review';
const kAppDashSearchEngine = 'app_dash_search_engine';
const kAppDefaultScreen = 'app_default_screen';
const kAppShowFediverseContent = 'app_show_fediverse_content';
const kAppDashboardConfig = 'app_dashboard_config';
// Will be overrided by the ProviderScope
final sharedPreferencesProvider = Provider<SharedPreferences>((ref) {
@@ -68,6 +69,19 @@ sealed class ThemeColors with _$ThemeColors {
_$ThemeColorsFromJson(json);
}
@freezed
sealed class DashboardConfig with _$DashboardConfig {
factory DashboardConfig({
required List<String> verticalLayouts,
required List<String> horizontalLayouts,
required bool showSearchBar,
required bool showClockAndCountdown,
}) = _DashboardConfig;
factory DashboardConfig.fromJson(Map<String, dynamic> json) =>
_$DashboardConfigFromJson(json);
}
@freezed
sealed class AppSettings with _$AppSettings {
const factory AppSettings({
@@ -94,6 +108,7 @@ sealed class AppSettings with _$AppSettings {
required String? dashSearchEngine,
required String? defaultScreen,
required bool showFediverseContent,
required DashboardConfig? dashboardConfig,
}) = _AppSettings;
}
@@ -126,6 +141,7 @@ class AppSettingsNotifier extends _$AppSettingsNotifier {
dashSearchEngine: prefs.getString(kAppDashSearchEngine),
defaultScreen: prefs.getString(kAppDefaultScreen),
showFediverseContent: prefs.getBool(kAppShowFediverseContent) ?? true,
dashboardConfig: _getDashboardConfigFromPrefs(prefs),
);
}
@@ -158,6 +174,18 @@ class AppSettingsNotifier extends _$AppSettingsNotifier {
}
}
DashboardConfig? _getDashboardConfigFromPrefs(SharedPreferences prefs) {
final jsonString = prefs.getString(kAppDashboardConfig);
if (jsonString == null) return null;
try {
final json = jsonDecode(jsonString);
return DashboardConfig.fromJson(json);
} catch (e) {
return null;
}
}
void setDefaultPoolId(String? value) {
final prefs = ref.read(sharedPreferencesProvider);
if (value != null) {
@@ -324,6 +352,17 @@ class AppSettingsNotifier extends _$AppSettingsNotifier {
prefs.setBool(kAppShowFediverseContent, value);
state = state.copyWith(showFediverseContent: value);
}
void setDashboardConfig(DashboardConfig? value) {
final prefs = ref.read(sharedPreferencesProvider);
if (value != null) {
final json = jsonEncode(value.toJson());
prefs.setString(kAppDashboardConfig, json);
} else {
prefs.remove(kAppDashboardConfig);
}
state = state.copyWith(dashboardConfig: value);
}
}
final updateInfoProvider =
@@ -340,4 +379,4 @@ class UpdateInfoNotifier extends Notifier<(String?, String?)> {
void setUpdate(String newVersion, String newChangelog) {
state = (newVersion, newChangelog);
}
}
}