Skip to content

[shared_preferences] Introduces SharedPreferencesWithCache.createWithoutWarmedUpCache #9776

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,26 @@ class SharedPreferencesWithCache {
SharedPreferencesAsync(options: sharedPreferencesOptions),
_cache = cache ?? <String, Object?>{};

/// Creates a new instance with the given options, but does not populate the
/// cache from the platform.
///
/// This constructor is synchronous and does not load data from disk, which
/// can be useful for dependency injection frameworks that do not support
/// asynchronous object creation. The cache must be populated by calling
/// [reloadCache] before it can be used.
static SharedPreferencesWithCache createWithoutWarmedUpCache({
SharedPreferencesOptions sharedPreferencesOptions =
const SharedPreferencesOptions(),
required SharedPreferencesWithCacheOptions cacheOptions,
Map<String, Object?>? cache,
}) {
return SharedPreferencesWithCache._create(
sharedPreferencesOptions: sharedPreferencesOptions,
cacheOptions: cacheOptions,
cache: cache,
);
}

/// Creates a new instance with the given options and reloads the cache from
/// the platform data.
static Future<SharedPreferencesWithCache> create({
Expand Down