Skip to content

Commit

Permalink
feat: add cameraViewFit key in SettingsProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmercerind committed Oct 11, 2022
1 parent ecde946 commit ab067e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/providers/settings_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SettingsProvider extends ChangeNotifier {
static final defaultSnoozedUntil = DateTime(1969, 7, 20, 20, 18, 04);
static const kDefaultNotificationClickAction =
NotificationClickAction.showFullscreenCamera;
static const kDefaultCameraViewFit = CameraViewFit.contain;

// Getters.
ThemeMode get themeMode => _themeMode;
Expand All @@ -43,6 +44,7 @@ class SettingsProvider extends ChangeNotifier {
DateTime get snoozedUntil => _snoozedUntil;
NotificationClickAction get notificationClickAction =>
_notificationClickAction;
CameraViewFit get cameraViewFit => _cameraViewFit;

// Setters.
set themeMode(ThemeMode value) {
Expand Down Expand Up @@ -91,11 +93,23 @@ class SettingsProvider extends ChangeNotifier {
});
}

set cameraViewFit(CameraViewFit value) {
_cameraViewFit = value;
notifyListeners();
Hive.openBox('hive').then((instance) {
instance.put(
kHiveCameraViewFit,
value.index,
);
});
}

late ThemeMode _themeMode;
late DateFormat _dateFormat;
late DateFormat _timeFormat;
late DateTime _snoozedUntil;
late NotificationClickAction _notificationClickAction;
late CameraViewFit _cameraViewFit;

/// Initializes the [ServersProvider] instance & fetches state from `async`
/// `package:hive` method-calls. Called before [runApp].
Expand Down Expand Up @@ -155,6 +169,11 @@ class SettingsProvider extends ChangeNotifier {
} else {
_notificationClickAction = kDefaultNotificationClickAction;
}
if (hive.containsKey(kHiveCameraViewFit)) {
_cameraViewFit = CameraViewFit.values[hive.get(kHiveCameraViewFit)!];
} else {
_cameraViewFit = kDefaultCameraViewFit;
}
notifyListeners();
}

Expand All @@ -167,3 +186,9 @@ enum NotificationClickAction {
showFullscreenCamera,
showEventsScreen,
}

enum CameraViewFit {
contain,
fill,
cover,
}
1 change: 1 addition & 0 deletions lib/utils/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const kHiveDateFormat = 'date_format';
const kHiveTimeFormat = 'time_format';
const kHiveSnoozedUntil = 'snoozed_until';
const kHiveNotificationClickAction = 'notification_click_action';
const kHiveCameraViewFit = 'camera_view_fit';

/// Used as frame buffer size in [DeviceTile], and calculating aspect ratio. Only relevant on desktop.
const kDeviceTileWidth = 640.0;
Expand Down

0 comments on commit ab067e7

Please sign in to comment.