-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persistent (Theme & Localization) Storage #31
Comments
📊 Current Status: Progress: 100% Implemented localization. 🔄 Additional Information: The default language has been set to English. |
@phoenixit99, I reviewed the code and found the following areas for improvement:
locator code/// The dependency injection container used throughout the application.
final locator = GetIt.instance;
/// Sets up and registers the shared preferences instance.
///
/// Ensures a `SharedPreferences` instance is available.
/// Creates a new instance if `param` is null.
/// Registers the instance as a singleton in `locator`.
///
/// **Parameters:**
///
/// * `param`: An optional `SharedPreferences` instance.
/// If provided, this instance will be used.
/// Otherwise, a new instance will be created.
///
/// **See also:**
///
/// * [SharedPreferences]
Future<SharedPreferences> setupSharedPreferences(
{SharedPreferences? param}) async {
final prefs = param ?? await SharedPreferences.getInstance();
return locator.registerSingleton<SharedPreferences>(prefs);
} 2- The tests related to language and theme have failed and need to be fixed. To write tests for locator code/// The dependency injection container used throughout the application.
final locator = GetIt.instance;
/// Initializes all necessary dependencies for the application.
///
/// This function registers all required services, repositories, and other dependencies
/// within the [locator] (GetIt instance).
void initDependencies() {
// ... some codes need using as singleton
}
/// A mock implementation of `SharedPreferences` for testing purposes.
class MockSharedPreferences extends Mock implements SharedPreferences {}
/// Sets up the testing environment.
///
/// Initializes the `TestWidgetsFlutterBinding`, creates a mock `SharedPreferences`
/// instance, initializes dependencies, and sets up the list of providers.
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late SharedPreferences sharedPreferencesObject;
late List<BloProvider> providers;
setUpAll(() {
sharedPreferencesObject = MockSharedPreferences();
setupSharedPreferences(param: sharedPreferencesObject).then((_) {
initDependencies();
providers = [
// ... scope of bloc providers
];
});
});
/// write main test code :
group(
'testing sample screen',
() {
/// bla bla bla
}
}
|
Thanks @esmaeil-ahmadipour . This has been really helpful and has saved me a lot of time. |
Overview
Feature Description
Implement persistent localization storage and app state initialization to ensure the selected language, theme, and other relevant settings persist across app restarts.
Click to expand the scenario
Scenario: Language and Theme Persistence on Restart
A user selects French as their preferred language and dark mode as their theme. When reopening the app, it should automatically display in French with the dark theme applied, without requiring the user to reselect them.
References
Platform-Specific Implementations:
Ensure language, theme, and app state are saved and loaded correctly across iOS, Android, and Web.
Related Issue:
Tools:
FOLDER STRUCTURE
Proposed Changes
SharedPreferences
.The text was updated successfully, but these errors were encountered: