Files
buzz/mobile/lib/features/settings/theme_option_sheets.dart
Arthur Garza a8cc77ac34 fix(mobile): keep a legacy chat color when Set changes only the mode (#9898)
Follow-up to #9894, addressing the review finding there.

## Problem
Some desktop chat colors (for example Cyan `#06b6d4`) have no exact
mobile swatch, so the Appearance picker shows the closest one (Jade).
Tapping **Set** after changing only Light/Dark/System saved Jade's value
(`#22c55e`), and that new color synced to every device.

## Fix
On Set, the saved accent is kept unless the user picked a different
color.

Also adds doc comments to `appearanceModeProvider` and
`AppearanceModeNotifier.setMode`.

## Tests
- The existing mode-only picker test now starts from legacy Cyan and
goes through the real `CommunityThemeNotifier.setPreference`, asserting
the synced preference is unchanged. It fails with the fix reverted.
- `just mobile-check` and `just mobile-test` pass.

## Try it
1. On desktop, set the chat color to a legacy color such as Cyan.
2. On mobile, open Settings → Appearance, change only Light/Dark/System,
tap Set.
3. Desktop and other devices still show Cyan.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Arthur Garza <arthur.garzajr@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 20:53:23 +00:00

160 lines
4.8 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:buzz/shared/theme/buzz_icons.dart';
import '../../shared/theme/theme.dart';
import '../../shared/widgets/modal_presentation.dart';
import '../../shared/widgets/duo_toolbar.dart';
import '../../shared/widgets/adaptive_conversation_pane.dart';
const appearanceModeOptions = <({ThemeMode mode, String label, IconData icon})>[
(mode: ThemeMode.light, label: 'Light', icon: BuzzIcons.sun),
(mode: ThemeMode.dark, label: 'Dark', icon: BuzzIcons.moon),
(mode: ThemeMode.system, label: 'System', icon: BuzzIcons.sunMoon),
];
String appearanceModeLabel(ThemeMode mode) =>
appearanceModeOptions.firstWhere((option) => option.mode == mode).label;
Future<void> showAccentColorPickerSheet({
required BuildContext context,
required ColorScheme colorScheme,
required int? pickedIndex,
required ValueChanged<int> onSelected,
}) => showBuzzModalBottomSheet<void>(
context: context,
title: 'Chat color',
showDragHandle: true,
builder: (_) => _AccentColorPicker(
compact:
DuoToolbarScope.maybeOf(context)?.strip != null &&
usesConversationPanes(context),
colorScheme: colorScheme,
pickedIndex: pickedIndex,
onSelected: onSelected,
),
);
class _AccentColorPicker extends HookConsumerWidget {
const _AccentColorPicker({
required this.colorScheme,
required this.compact,
required this.pickedIndex,
required this.onSelected,
});
final ColorScheme colorScheme;
final bool compact;
/// The swatch the user already tapped, or null to follow the saved color.
final int? pickedIndex;
final ValueChanged<int> onSelected;
@override
Widget build(BuildContext context, WidgetRef ref) {
final picked = useState(pickedIndex);
// Until a tap, the marker follows the saved color, including a sync.
final saved = ref.watch(
communityThemeProvider.select((t) => chatColorIndex(t.accent)),
);
final selected = picked.value ?? saved;
return SafeArea(
top: false,
child: Padding(
padding: const EdgeInsets.fromLTRB(
Grid.gutter,
Grid.xxs,
Grid.gutter,
Grid.xs,
),
child: Align(
heightFactor: 1,
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: compact ? 320 : double.infinity,
),
child: GridView.builder(
key: const ValueKey('accent-selection-grid'),
shrinkWrap: true,
primary: false,
padding: EdgeInsets.zero,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
crossAxisSpacing: Grid.xxs,
mainAxisSpacing: Grid.xs,
),
itemCount: chatColorChoices.length,
itemBuilder: (context, index) => _AccentSheetOption(
index: index,
color: chatColorForScheme(colorScheme, index),
selected: selected == index,
onTap: () {
unawaited(HapticFeedback.selectionClick());
picked.value = index;
onSelected(index);
},
),
),
),
),
),
);
}
}
class _AccentSheetOption extends StatelessWidget {
const _AccentSheetOption({
required this.index,
required this.color,
required this.selected,
required this.onTap,
});
final int index;
final Color color;
final bool selected;
final VoidCallback onTap;
@override
Widget build(BuildContext context) => Semantics(
label: '${chatColorChoices[index].name} chat color',
button: true,
selected: selected,
child: InkResponse(
key: ValueKey('accent-option-$index'),
onTap: onTap,
radius: 36,
child: Center(
child: Container(
key: ValueKey('accent-swatch-$index'),
width: 64,
height: 64,
padding: const EdgeInsets.all(5),
decoration: BoxDecoration(
color: color,
shape: BoxShape.circle,
border: Border.all(color: context.colors.outlineVariant),
),
child: selected
? DecoratedBox(
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: color.computeLuminance() > 0.55
? const Color(0xFF111111)
: Colors.white,
width: 3,
),
),
)
: null,
),
),
),
);
}