Skip to content

Commit a8cc77a

Browse files
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>
1 parent e600cdb commit a8cc77a

4 files changed

Lines changed: 259 additions & 31 deletions

File tree

‎mobile/lib/features/settings/theme_option_sheets.dart‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:async';
33
import 'package:flutter/material.dart';
44
import 'package:flutter/services.dart';
55
import 'package:flutter_hooks/flutter_hooks.dart';
6+
import 'package:hooks_riverpod/hooks_riverpod.dart';
67
import 'package:buzz/shared/theme/buzz_icons.dart';
78

89
import '../../shared/theme/theme.dart';
@@ -22,7 +23,7 @@ String appearanceModeLabel(ThemeMode mode) =>
2223
Future<void> showAccentColorPickerSheet({
2324
required BuildContext context,
2425
required ColorScheme colorScheme,
25-
required int selectedIndex,
26+
required int? pickedIndex,
2627
required ValueChanged<int> onSelected,
2728
}) => showBuzzModalBottomSheet<void>(
2829
context: context,
@@ -33,27 +34,34 @@ Future<void> showAccentColorPickerSheet({
3334
DuoToolbarScope.maybeOf(context)?.strip != null &&
3435
usesConversationPanes(context),
3536
colorScheme: colorScheme,
36-
initialIndex: selectedIndex,
37+
pickedIndex: pickedIndex,
3738
onSelected: onSelected,
3839
),
3940
);
4041

41-
class _AccentColorPicker extends HookWidget {
42+
class _AccentColorPicker extends HookConsumerWidget {
4243
const _AccentColorPicker({
4344
required this.colorScheme,
4445
required this.compact,
45-
required this.initialIndex,
46+
required this.pickedIndex,
4647
required this.onSelected,
4748
});
4849

4950
final ColorScheme colorScheme;
5051
final bool compact;
51-
final int initialIndex;
52+
53+
/// The swatch the user already tapped, or null to follow the saved color.
54+
final int? pickedIndex;
5255
final ValueChanged<int> onSelected;
5356

5457
@override
55-
Widget build(BuildContext context) {
56-
final selected = useState(initialIndex);
58+
Widget build(BuildContext context, WidgetRef ref) {
59+
final picked = useState(pickedIndex);
60+
// Until a tap, the marker follows the saved color, including a sync.
61+
final saved = ref.watch(
62+
communityThemeProvider.select((t) => chatColorIndex(t.accent)),
63+
);
64+
final selected = picked.value ?? saved;
5765
return SafeArea(
5866
top: false,
5967
child: Padding(
@@ -83,10 +91,10 @@ class _AccentColorPicker extends HookWidget {
8391
itemBuilder: (context, index) => _AccentSheetOption(
8492
index: index,
8593
color: chatColorForScheme(colorScheme, index),
86-
selected: selected.value == index,
94+
selected: selected == index,
8795
onTap: () {
8896
unawaited(HapticFeedback.selectionClick());
89-
selected.value = index;
97+
picked.value = index;
9098
onSelected(index);
9199
},
92100
),

‎mobile/lib/features/settings/theme_picker_page/theme_preview_sheet.dart‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ class _ThemePreviewExperience extends HookConsumerWidget {
1010
@override
1111
Widget build(BuildContext context, WidgetRef ref) {
1212
final inRail = DuoToolbarScope.maybeOf(context)?.strip != null;
13-
final stored = ref.read(communityThemeProvider);
1413
final draftMode = useState(ref.read(appearanceModeProvider));
15-
final draftAccent = useState(chatColorIndex(stored.accent));
14+
final pickedAccent = useState<int?>(null);
15+
// Until the user taps a swatch, the preview follows the saved color,
16+
// including one synced from another device while this sheet is open.
17+
final savedAccent = ref.watch(
18+
communityThemeProvider.select((t) => chatColorIndex(t.accent)),
19+
);
20+
final draftAccent = pickedAccent.value ?? savedAccent;
1621
final platformBrightness = MediaQuery.platformBrightnessOf(context);
1722
final reduceMotion = MediaQuery.disableAnimationsOf(context);
1823
final brightness = switch (draftMode.value) {
@@ -36,22 +41,27 @@ class _ThemePreviewExperience extends HookConsumerWidget {
3641
void chooseColor() => showAccentColorPickerSheet(
3742
context: context,
3843
colorScheme: selectedBaseScheme,
39-
selectedIndex: draftAccent.value,
40-
onSelected: (index) => draftAccent.value = index,
44+
pickedIndex: pickedAccent.value,
45+
onSelected: (index) => pickedAccent.value = index,
4146
);
4247

4348
void applySelection() {
4449
unawaited(HapticFeedback.mediumImpact());
4550
ref.read(appearanceModeProvider.notifier).setMode(draftMode.value);
4651
// Only the chat color syncs. The synced theme and followSystem stay as
47-
// they are, so this device's mode never changes other devices.
52+
// they are, so this device's mode never changes other devices. A color
53+
// the user did not tap keeps its saved value, so a legacy color that
54+
// only maps to a swatch is not republished as that swatch.
4855
final current = ref.read(communityThemeProvider);
4956
ref
5057
.read(communityThemeProvider.notifier)
5158
.setPreference(
5259
CommunityThemePreference(
5360
theme: current.theme,
54-
accent: chatColorChoices[draftAccent.value].wireValue,
61+
accent: switch (pickedAccent.value) {
62+
final index? => chatColorChoices[index].wireValue,
63+
null => current.accent,
64+
},
5565
followSystem: current.followSystem,
5666
),
5767
);
@@ -89,7 +99,7 @@ class _ThemePreviewExperience extends HookConsumerWidget {
8999
child: _ThemePreviewPage(
90100
theme: selectedEntry,
91101
mode: draftMode.value,
92-
accentIndex: draftAccent.value,
102+
accentIndex: draftAccent,
93103
platformBrightness: platformBrightness,
94104
),
95105
),
@@ -116,7 +126,7 @@ class _ThemePreviewExperience extends HookConsumerWidget {
116126
semanticLabel: 'Chat color',
117127
color: chatColorForScheme(
118128
selectedBaseScheme,
119-
draftAccent.value,
129+
draftAccent,
120130
),
121131
onTap: chooseColor,
122132
),
@@ -161,7 +171,7 @@ class _ThemePreviewExperience extends HookConsumerWidget {
161171
_PreviewSheetCircleAction(
162172
key: const ValueKey('theme-preview-accent-action-button'),
163173
semanticLabel: 'Chat color',
164-
color: chatColorForScheme(selectedBaseScheme, draftAccent.value),
174+
color: chatColorForScheme(selectedBaseScheme, draftAccent),
165175
onTap: chooseColor,
166176
),
167177
_AppearanceCycleAction(
@@ -213,10 +223,7 @@ class _ThemePreviewExperience extends HookConsumerWidget {
213223
child: _PreviewSheetCircleAction(
214224
key: const ValueKey('theme-preview-accent-action-button'),
215225
semanticLabel: 'Chat color',
216-
color: chatColorForScheme(
217-
selectedBaseScheme,
218-
draftAccent.value,
219-
),
226+
color: chatColorForScheme(selectedBaseScheme, draftAccent),
220227
onTap: chooseColor,
221228
),
222229
),

‎mobile/lib/shared/theme/theme_provider.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class AppearanceModeNotifier extends Notifier<ThemeMode> {
3333
ThemeMode.system;
3434
}
3535

36+
/// Saves [mode] on this device only; it is never synced.
3637
void setMode(ThemeMode mode) {
3738
if (mode == state) return;
3839
state = mode;
@@ -42,6 +43,7 @@ class AppearanceModeNotifier extends Notifier<ThemeMode> {
4243
}
4344
}
4445

46+
/// This device's Light, Dark or System choice. See [AppearanceModeNotifier].
4547
final appearanceModeProvider =
4648
NotifierProvider<AppearanceModeNotifier, ThemeMode>(
4749
AppearanceModeNotifier.new,

0 commit comments

Comments
 (0)