fix(profile): apply a saved language to the running app - #96
Merged
Conversation
Saving a locale persisted it and confirmed it with a toast, and then the app went on speaking the old language until its next boot. Nothing re-pointed the translator after `Auth.restore()`, so the one screen whose entire purpose is changing the language appeared to do nothing. `doUpdateProfile` now applies it through `Lang.setLocale`, which loads the catalogue and rebuilds the tree. It lives here rather than in the views because five call sites pass `language` to this method: the dedicated language page, the profile settings view (twice) and the profile sub-page view (twice). Two details that are load-bearing rather than incidental: - It is scheduled AFTER the current frame. `Lang.setLocale` calls `Magic.reload()`, which swaps a key above the whole tree and unmounts the caller that is still inside its own `await` on this method. The language page, for one, clears an isolated save spinner in a `finally` on a `ValueNotifier` its own state owns and disposes, so rebuilding before that runs would use it after disposal. - It asks for that frame explicitly. `addPostFrameCallback` does not request one, and an idle Flutter app stops producing frames, so without `scheduleFrame()` the switch could sit unapplied until the next interaction happened to schedule one. Measured: a post-frame callback registered outside a build does not fire on `tester.pump()` alone, and does fire after `scheduleFrame()`. A no-op when the language is absent or already current, so re-saving a profile without touching the selector does not flash a rebuild.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Saving a locale persisted it and confirmed it with a toast, and then the app went on speaking the old language until its next boot. Nothing re-pointed the translator after
Auth.restore(), so/settings/language, the one screen whose entire purpose is changing the language, appeared to do nothing.doUpdateProfilenow applies it throughLang.setLocale, which loads the catalogue and rebuilds the tree.Why here and not in the views
Five call sites pass
languageto this method:magic_starter_language_view.dart:79magic_starter_profile_settings_view.dart:196and:1372magic_starter_profile_sub_page_view.dart:433and:537Duplicating the application five times would guarantee one of them drifts.
Two details that are load-bearing
It is scheduled after the current frame.
Lang.setLocalecallsMagic.reload()->MagicAppWidget.restart(), which swaps aUniqueKeyabove the whole tree and therefore unmounts the caller that is still inside its ownawaiton this method. The language page clears an isolated save spinner in afinally, on aValueNotifierits own state owns and disposes, so rebuilding before that runs would use it after disposal. Letting the caller finish costs one frame and keeps every call site correct without any of them knowing.It asks for that frame explicitly.
addPostFrameCallbackdoes not request a frame, and an idle Flutter app stops producing them, so withoutscheduleFrame()the switch could sit unapplied until the next interaction happened to schedule one. That is not a guess:A no-op when the language is absent or already current, so re-saving a profile without touching the selector does not flash a rebuild.
Testing
Two
testWidgetscases inmagic_starter_profile_controller_test.dart: a changed language switchesLang.current, an unchanged one does not. The first was confirmed to fail with the call removed.flutter test: 1255 passing.flutter analyze --no-fatal-infos: clean.dart format .: applied.Also verified end to end in a consuming app (uptizm, which resolves this package by path). Tapping Save on
/settings/languagewith Türkçe selected, with no reload, turned the page title "Language" into "Dil", "Save" into "Kaydet" and the bottom tab bar into "Ana Sayfa / İzleyiciler / Olaylar / Durum". Before this change the same tap left every one of them in English.