UserPreferencesModel.fromMap constructor

UserPreferencesModel.fromMap(
  1. Map<String, dynamic> map
)

Creates user preferences from a map.

Implementation

factory UserPreferencesModel.fromMap(Map<String, dynamic> map) {
  return UserPreferencesModel(
    globalNotificationsEnabled: map.parseDefault<bool>(
      'globalNotificationsEnabled',
      true,
    ),
    soundEnabled: map.parseDefault<bool>('soundEnabled', true),
    vibrationEnabled: map.parseDefault<bool>('vibrationEnabled', true),
    badgeEnabled: map.parseDefault<bool>('badgeEnabled', true),
    alertStyle: NotificationAlertStyle.values.firstWhere(
      (NotificationAlertStyle e) => e.name.compareWithoutCase(
        map.parseDefault<String>(
          'alertStyle',
          NotificationAlertStyle.banner.name,
        ),
      ),
      orElse: () => NotificationAlertStyle.banner,
    ),
    showPreviews: map.parseDefault<bool>('showPreviews', true),
    groupNotifications: map.parseDefault<bool>('groupNotifications', true),
    notificationHistory: map.parseDefault<bool>('notificationHistory', true),
    criticalAlertsEnabled: map.parseDefault<bool>(
      'criticalAlertsEnabled',
      false,
    ),
    scheduledDelivery: map.parseDefault<bool>('scheduledDelivery', false),
    quietHours: map.parse<Map<String, dynamic>>('quietHours') != null
        ? QuietHoursSettings.fromMap(
            map.parseDefault<Map<String, dynamic>>(
              'quietHours',
              const QuietHoursSettings().toMap(),
            ),
          )
        : const QuietHoursSettings(),
    categoryPreferences: _parseCategoryPreferences(
      map.parse<Map<String, dynamic>>('categoryPreferences'),
    ),
    blockedSenders: map.parseDefault<List<String>>(
      'blockedSenders',
      <String>[],
    ),
    allowedSenders: map.parseDefault<List<String>>(
      'allowedSenders',
      <String>[],
    ),
    lastUpdated: map.parse<DateTime>('lastUpdated'),
  );
}