@@ -2,9 +2,11 @@ import 'dart:convert';
22
33import 'package:collection/collection.dart' ;
44import 'package:dart_mappable/dart_mappable.dart' ;
5+ import 'package:flow/src/generated/i18n/app_localizations.dart' ;
56import 'package:flutter/material.dart' ;
67import 'package:flutter_bloc/flutter_bloc.dart' ;
78import 'package:material_leap/material_leap.dart' ;
9+ import 'package:phosphor_flutter/phosphor_flutter.dart' ;
810import 'package:shared_preferences/shared_preferences.dart' ;
911import 'package:timezone/timezone.dart' as tz;
1012import 'package:flutter_local_notifications/flutter_local_notifications.dart' ;
@@ -61,6 +63,35 @@ final class ThemeModeMapper extends SimpleMapper<ThemeMode> {
6163 }
6264}
6365
66+ @MappableEnum ()
67+ enum CalendarView {
68+ list,
69+ day,
70+ week,
71+ month,
72+ pending;
73+
74+ String getLocalizedName (BuildContext context) {
75+ return switch (this ) {
76+ CalendarView .list => AppLocalizations .of (context).list,
77+ CalendarView .day => AppLocalizations .of (context).day,
78+ CalendarView .week => AppLocalizations .of (context).week,
79+ CalendarView .month => AppLocalizations .of (context).month,
80+ CalendarView .pending => AppLocalizations .of (context).pending,
81+ };
82+ }
83+
84+ IconGetter get icon {
85+ return switch (this ) {
86+ CalendarView .list => PhosphorIcons .list,
87+ CalendarView .day => PhosphorIcons .calendar,
88+ CalendarView .week => PhosphorIcons .columns,
89+ CalendarView .month => PhosphorIcons .gridNine,
90+ CalendarView .pending => PhosphorIcons .clock,
91+ };
92+ }
93+ }
94+
6495@MappableClass (includeCustomMappers: [ThemeModeMapper ()])
6596class FlowSettings with FlowSettingsMappable , LeapSettings {
6697 static const String localeKey = 'locale' ;
@@ -84,6 +115,8 @@ class FlowSettings with FlowSettingsMappable, LeapSettings {
84115 final bool highContrast;
85116 static const String alarmsKey = 'alarms' ;
86117 final List <Alarm > alarms;
118+ static const String calendarViewKey = 'calendarView' ;
119+ final CalendarView calendarView;
87120
88121 const FlowSettings ({
89122 this .locale = '' ,
@@ -96,6 +129,7 @@ class FlowSettings with FlowSettingsMappable, LeapSettings {
96129 this .density = ThemeDensity .system,
97130 this .highContrast = false ,
98131 this .alarms = const [],
132+ this .calendarView = CalendarView .list,
99133 });
100134
101135 factory FlowSettings .fromPrefs (SharedPreferences prefs) => FlowSettings (
@@ -125,6 +159,9 @@ class FlowSettings with FlowSettingsMappable, LeapSettings {
125159 ? .map ((e) => AlarmMapper .fromJson (e))
126160 .toList () ??
127161 [],
162+ calendarView: CalendarView .values.byName (
163+ prefs.getString (calendarViewKey) ?? 'list' ,
164+ ),
128165 );
129166 Future <void > saveThemeMode (SharedPreferences prefs) =>
130167 prefs.setString (themeModeKey, themeMode.name);
@@ -148,6 +185,8 @@ class FlowSettings with FlowSettingsMappable, LeapSettings {
148185 prefs.setBool (highContrastKey, highContrast);
149186 Future <void > saveAlarms (SharedPreferences prefs) =>
150187 prefs.setStringList (alarmsKey, alarms.map ((e) => e.toJson ()).toList ());
188+ Future <void > saveCalendarView (SharedPreferences prefs) =>
189+ prefs.setString (calendarViewKey, calendarView.name);
151190
152191 Future <void > save (SharedPreferences prefs) async {
153192 await saveThemeMode (prefs);
@@ -160,6 +199,7 @@ class FlowSettings with FlowSettingsMappable, LeapSettings {
160199 await saveDensity (prefs);
161200 await saveHighContrast (prefs);
162201 await saveAlarms (prefs);
202+ await saveCalendarView (prefs);
163203 }
164204}
165205
@@ -271,6 +311,12 @@ class SettingsCubit extends Cubit<FlowSettings>
271311 return _runSave (newState.saveAlarms);
272312 }
273313
314+ Future <void > changeCalendarView (CalendarView view) {
315+ final newState = state.copyWith (calendarView: view);
316+ emit (newState);
317+ return _runSave (newState.saveCalendarView);
318+ }
319+
274320 Future <void > importSettings (String data) {
275321 final settings = FlowSettingsMapper .fromJson (
276322 data,
0 commit comments