Skip to content

Commit 4e41d90

Browse files
fadi-georgeclaude
andcommitted
chore: [SDK-5608] reset language picker on login and logout without setLanguage
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b1152ed commit 4e41d90

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

‎examples/build.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ OneSignal.User.addObserver(...)
166166
- The Push section shows a read-only **Status** row above the **Opted In** toggle: `Subscribed` when `pushSubscription.optedIn` is true, notification permission is granted, and a push token is present; otherwise `Unsubscribed`. `AppViewModel.isPushSubscribed` derives this from the push subscription and permission observers.
167167

168168
### Language
169-
- The User section has a **Language** dropdown (`Device Default` plus the shared language list) after External ID. The selection is cached in `PreferencesService` and reset to `Device Default` on logout.
170-
- `Device Default` calls `OneSignal.User.setLanguage('')`, which the native SDK resolves to the device language.
169+
- The User section has a **Language** dropdown (`Device Default` plus the shared language list) after External ID. The selection is cached in `PreferencesService`. Login and logout reset the picker to `Device Default` locally (clear the cached value and UI state) without calling `OneSignal.User.setLanguage`, since `''` would send the device language and overwrite the user's backend value.
170+
- Selecting `Device Default` in the picker calls `OneSignal.User.setLanguage('')`, which the native SDK resolves to the device language.
171171
- `DropdownButton` sizes itself to its widest option, so set `alignment: AlignmentDirectional.centerEnd` to keep the selected value next to the arrow, and `menuMaxHeight` so the open menu doesn't cover the screen.
172172

173173
### SnackBar Messages

‎examples/demo-pods/lib/viewmodels/app_viewmodel.dart‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ class AppViewModel extends ChangeNotifier {
244244
try {
245245
await OneSignal.login(externalUserId);
246246
await _prefs.setExternalUserId(externalUserId);
247+
await _resetLanguagePicker();
247248
debugPrint('Logged in as: $externalUserId');
248249
// Drive the post-login fetch ourselves so isLoading always clears,
249250
// even when OneSignal.login() doesn't emit a user change event
@@ -269,14 +270,22 @@ class AppViewModel extends ChangeNotifier {
269270
try {
270271
await OneSignal.logout();
271272
await _prefs.setExternalUserId(null);
272-
await setLanguage('');
273+
await _resetLanguagePicker();
273274
debugPrint('Logged out');
274275
} catch (e) {
275276
debugPrint('Logout error: $e');
276277
}
277278
}
278279

279280
// Language
281+
// Clears only the cached choice. setLanguage('') would send the device
282+
// language and overwrite the user's backend value.
283+
Future<void> _resetLanguagePicker() async {
284+
_language = '';
285+
notifyListeners();
286+
await _prefs.setLanguage('');
287+
}
288+
280289
Future<void> setLanguage(String language) async {
281290
_language = language;
282291
notifyListeners();

‎examples/demo/lib/viewmodels/app_viewmodel.dart‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ class AppViewModel extends ChangeNotifier {
283283
try {
284284
await OneSignal.login(externalUserId);
285285
await _prefs.setExternalUserId(externalUserId);
286+
await _resetLanguagePicker();
286287
LogService.info('Logged in as: $externalUserId');
287288
// The User observer runs fetchUserDataFromApi once the new onesignalId
288289
// is assigned; that call clears _isLoading in its finally.
@@ -305,14 +306,22 @@ class AppViewModel extends ChangeNotifier {
305306
try {
306307
await OneSignal.logout();
307308
await _prefs.setExternalUserId(null);
308-
await setLanguage('');
309+
await _resetLanguagePicker();
309310
LogService.info('Logged out');
310311
} catch (e) {
311312
LogService.error('Logout error: $e');
312313
}
313314
}
314315

315316
// Language
317+
// Clears only the cached choice. setLanguage('') would send the device
318+
// language and overwrite the user's backend value.
319+
Future<void> _resetLanguagePicker() async {
320+
_language = '';
321+
notifyListeners();
322+
await _prefs.setLanguage('');
323+
}
324+
316325
Future<void> setLanguage(String language) async {
317326
_language = language;
318327
notifyListeners();

0 commit comments

Comments
 (0)