Skip to content

Commit

Permalink
chore(windows, linux): Saving shared preferences in a different file …
Browse files Browse the repository at this point in the history
…in debug mode.
  • Loading branch information
Skyost committed Jan 11, 2025
1 parent a73b9db commit 7ea7b1e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/utils/shared_preferences_with_prefix.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart';
import 'package:open_authenticator/utils/platform.dart';
import 'package:open_authenticator/utils/utils.dart';
import 'package:rate_my_app/rate_my_app.dart';
import 'package:shared_preferences/shared_preferences.dart';
// ignore: depend_on_referenced_packages
import 'package:shared_preferences_linux/shared_preferences_linux.dart';
// ignore: depend_on_referenced_packages
import 'package:shared_preferences_platform_interface/types.dart';
// ignore: depend_on_referenced_packages
import 'package:shared_preferences_windows/shared_preferences_windows.dart';

/// Allows to use [SharedPreferencesWithCache] with a prefix.
class SharedPreferencesWithPrefix {
Expand All @@ -27,8 +34,17 @@ class SharedPreferencesWithPrefix {
}

/// Creates a new shared preferences with prefix instance.
static Future<SharedPreferencesWithPrefix> _createSharedPreferencesWithPrefix(String prefix) async => SharedPreferencesWithPrefix._(
static Future<SharedPreferencesWithPrefix> _createSharedPreferencesWithPrefix(
String prefix, {
String fileName = kDebugMode ? 'shared_preferences_debug' : 'shared_preferences',
}) async =>
SharedPreferencesWithPrefix._(
sharedPreferences: await SharedPreferencesWithCache.create(
sharedPreferencesOptions: switch (currentPlatform) {
Platform.windows => SharedPreferencesWindowsOptions(fileName: fileName),
Platform.linux => SharedPreferencesLinuxOptions(fileName: fileName),
_ => SharedPreferencesOptions(),
},
cacheOptions: SharedPreferencesWithCacheOptions(),
),
prefix: prefix,
Expand Down

0 comments on commit 7ea7b1e

Please sign in to comment.