mirror of
https://github.com/block/buzz.git
synced 2026-11-13 04:41:12 +00:00
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> Signed-off-by: kenny lopez <klopez4212@gmail.com>
72 lines
2.4 KiB
Dart
72 lines
2.4 KiB
Dart
part of '../settings_page.dart';
|
|
|
|
bool _notificationsVisible(WidgetRef ref) {
|
|
if (defaultTargetPlatform != TargetPlatform.iOS) return false;
|
|
final community = ref.watch(activeCommunityProvider).value;
|
|
if (community == null) return false;
|
|
final capability = ref.watch(currentRelayPushDescriptorProvider);
|
|
return (!capability.isLoading &&
|
|
!capability.hasError &&
|
|
capability.value != null) ||
|
|
community.pushNotificationsEnabled ||
|
|
community.pushSubscriptionState.pendingTombstoneGeneration != null;
|
|
}
|
|
|
|
class _NotificationsSection extends ConsumerWidget {
|
|
const _NotificationsSection();
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
if (!_notificationsVisible(ref)) return const SizedBox.shrink();
|
|
final community = ref.watch(activeCommunityProvider).value!;
|
|
final capability = ref.watch(currentRelayPushDescriptorProvider);
|
|
final hasCapability =
|
|
!capability.isLoading &&
|
|
!capability.hasError &&
|
|
capability.value != null;
|
|
final canToggle = hasCapability || community.pushNotificationsEnabled;
|
|
|
|
void setEnabled(bool enabled) {
|
|
unawaited(
|
|
ref
|
|
.read(communityListProvider.notifier)
|
|
.setPushNotificationsEnabled(community.id, enabled),
|
|
);
|
|
}
|
|
|
|
return AppListCard(
|
|
verticalPadding: Grid.twelve,
|
|
children: [
|
|
MergeSemantics(
|
|
key: const ValueKey('push-notifications-setting'),
|
|
child: Stack(
|
|
alignment: Alignment.centerRight,
|
|
children: [
|
|
AppListRow(
|
|
key: const ValueKey('push-notifications-enabled'),
|
|
title: 'Notifications',
|
|
// Reserve horizontal room without letting the switch's 48dp
|
|
// layout height expand this single-line row.
|
|
trailing: const SizedBox(width: 60),
|
|
onTap: canToggle
|
|
? () => setEnabled(!community.pushNotificationsEnabled)
|
|
: null,
|
|
),
|
|
Positioned.fill(
|
|
right: Grid.xs,
|
|
child: Align(
|
|
alignment: Alignment.centerRight,
|
|
child: Switch.adaptive(
|
|
value: community.pushNotificationsEnabled,
|
|
onChanged: canToggle ? setEnabled : null,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|