import 'package:awesome_extensions/awesome_extensions.dart'; import 'package:flutter/material.dart'; import 'package:flutter_translate/flutter_translate.dart'; import '../../settings/settings.dart'; import '../../theme/theme.dart'; import '../notifications.dart'; Widget buildSettingsPageNotificationPreferences( {required BuildContext context}) { final theme = Theme.of(context); final scale = theme.extension()!; final scaleConfig = theme.extension()!; final textTheme = theme.textTheme; final preferencesRepository = PreferencesRepository.instance; final notificationsPreference = preferencesRepository.value.notificationsPreference; Future updatePreferences( NotificationsPreference newNotificationsPreference) async { final newPrefs = preferencesRepository.value .copyWith(notificationsPreference: newNotificationsPreference); await preferencesRepository.set(newPrefs); } List> notificationModeItems() { final out = >[]; final items = [ (NotificationMode.none, true, translate('settings_page.none')), (NotificationMode.inApp, true, translate('settings_page.in_app')), (NotificationMode.push, false, translate('settings_page.push')), ( NotificationMode.inAppOrPush, true, translate('settings_page.in_app_or_push') ), ]; for (final x in items) { out.add(DropdownMenuItem( value: x.$1, enabled: x.$2, child: Text( x.$3, softWrap: false, style: textTheme.labelMedium, textAlign: TextAlign.center, ).fit(fit: BoxFit.scaleDown))); } return out; } List> soundEffectItems() { final out = >[]; final items = [ (SoundEffect.none, true, translate('settings_page.none')), (SoundEffect.bonk, true, translate('settings_page.bonk')), (SoundEffect.boop, true, translate('settings_page.boop')), (SoundEffect.baDeep, true, translate('settings_page.badeep')), (SoundEffect.beepBaDeep, true, translate('settings_page.beep_badeep')), (SoundEffect.custom, false, translate('settings_page.custom')), ]; for (final x in items) { out.add(DropdownMenuItem( value: x.$1, enabled: x.$2, child: Text( x.$3, softWrap: false, style: textTheme.labelMedium, textAlign: TextAlign.center, ))); } return out; } List> messageNotificationContentItems() { final out = >[]; final items = [ ( MessageNotificationContent.nameAndContent, true, translate('settings_page.name_and_content') ), ( MessageNotificationContent.nameOnly, true, translate('settings_page.name_only') ), ( MessageNotificationContent.nothing, true, translate('settings_page.nothing') ), ]; for (final x in items) { out.add(DropdownMenuItem( value: x.$1, enabled: x.$2, child: Text( x.$3, softWrap: false, style: textTheme.labelMedium, textAlign: TextAlign.center, ))); } return out; } return InputDecorator( decoration: InputDecoration( labelText: translate('settings_page.notifications'), border: OutlineInputBorder( borderRadius: BorderRadius.circular(8 * scaleConfig.borderRadiusScale), borderSide: BorderSide(width: 2, color: scale.primaryScale.border), ), ), child: Column(mainAxisSize: MainAxisSize.min, children: [ // Display Beta Warning StyledCheckbox( label: translate('settings_page.display_beta_warning'), value: notificationsPreference.displayBetaWarning, onChanged: (value) async { final newNotificationsPreference = notificationsPreference.copyWith(displayBetaWarning: value); await updatePreferences(newNotificationsPreference); }), // Enable Badge StyledCheckbox( label: translate('settings_page.enable_badge'), value: notificationsPreference.enableBadge, onChanged: (value) async { final newNotificationsPreference = notificationsPreference.copyWith(enableBadge: value); await updatePreferences(newNotificationsPreference); }), // Enable Notifications StyledCheckbox( label: translate('settings_page.enable_notifications'), value: notificationsPreference.enableNotifications, onChanged: (value) async { final newNotificationsPreference = notificationsPreference.copyWith(enableNotifications: value); await updatePreferences(newNotificationsPreference); }), StyledDropdown( items: messageNotificationContentItems(), value: notificationsPreference.messageNotificationContent, decoratorLabel: translate('settings_page.message_notification_content'), onChanged: !notificationsPreference.enableNotifications ? null : (value) async { final newNotificationsPreference = notificationsPreference .copyWith(messageNotificationContent: value); await updatePreferences(newNotificationsPreference); }, ).paddingLTRB(0, 4.scaled(context), 0, 4.scaled(context)), // Notifications Table( defaultVerticalAlignment: TableCellVerticalAlignment.middle, children: [ TableRow(children: [ Text(translate('settings_page.event'), textAlign: TextAlign.center, style: textTheme.titleMedium!.copyWith( color: scale.primaryScale.border, decorationColor: scale.primaryScale.border, decoration: TextDecoration.underline)) .paddingAll(8.scaled(context)), Text(translate('settings_page.delivery'), textAlign: TextAlign.center, style: textTheme.titleMedium!.copyWith( color: scale.primaryScale.border, decorationColor: scale.primaryScale.border, decoration: TextDecoration.underline)) .paddingAll(8.scaled(context)), Text(translate('settings_page.sound'), textAlign: TextAlign.center, style: textTheme.titleMedium!.copyWith( color: scale.primaryScale.border, decorationColor: scale.primaryScale.border, decoration: TextDecoration.underline)) .paddingAll(8.scaled(context)), ]), TableRow(children: [ // Invitation accepted Text( textAlign: TextAlign.right, translate('settings_page.invitation_accepted')) .paddingAll(4.scaled(context)), StyledDropdown( items: notificationModeItems(), value: notificationsPreference.onInvitationAcceptedMode, onChanged: !notificationsPreference.enableNotifications ? null : (value) async { final newNotificationsPreference = notificationsPreference.copyWith( onInvitationAcceptedMode: value); await updatePreferences(newNotificationsPreference); }, ).paddingAll(4.scaled(context)), StyledDropdown( items: soundEffectItems(), value: notificationsPreference.onInvitationAcceptedSound, onChanged: !notificationsPreference.enableNotifications ? null : (value) async { final newNotificationsPreference = notificationsPreference.copyWith( onInvitationAcceptedSound: value); await updatePreferences(newNotificationsPreference); }, ).paddingLTRB( 4.scaled(context), 4.scaled(context), 0, 4.scaled(context)) ]), // Message received TableRow(children: [ Text( textAlign: TextAlign.right, translate('settings_page.message_received')) .paddingAll(4.scaled(context)), StyledDropdown( items: notificationModeItems(), value: notificationsPreference.onMessageReceivedMode, onChanged: !notificationsPreference.enableNotifications ? null : (value) async { final newNotificationsPreference = notificationsPreference.copyWith( onMessageReceivedMode: value); await updatePreferences(newNotificationsPreference); }, ).paddingAll(4), StyledDropdown( items: soundEffectItems(), value: notificationsPreference.onMessageReceivedSound, onChanged: !notificationsPreference.enableNotifications ? null : (value) async { final newNotificationsPreference = notificationsPreference.copyWith( onMessageReceivedSound: value); await updatePreferences(newNotificationsPreference); }, ).paddingLTRB( 4.scaled(context), 4.scaled(context), 0, 4.scaled(context)) ]), // Message sent TableRow(children: [ Text( textAlign: TextAlign.right, translate('settings_page.message_sent')) .paddingAll(4.scaled(context)), const SizedBox.shrink(), StyledDropdown( items: soundEffectItems(), value: notificationsPreference.onMessageSentSound, onChanged: !notificationsPreference.enableNotifications ? null : (value) async { final newNotificationsPreference = notificationsPreference.copyWith( onMessageSentSound: value); await updatePreferences(newNotificationsPreference); }, ).paddingLTRB( 4.scaled(context), 4.scaled(context), 0, 4.scaled(context)) ]), ]) ]).paddingAll(8.scaled(context)), ); }